mapbox / mapbox-gl-native-ios

Interactive, thoroughly customizable maps for iOS powered by vector tiles and OpenGL
https://www.mapbox.com/mobile/
Other
210 stars 121 forks source link

NSExpression addition "mgl_does:have:" can't evaluates ! #591

Open alanchenboy opened 3 years ago

alanchenboy commented 3 years ago

Platform: iOS Mapbox SDK version: Lastest 2022.2

Steps to trigger behavior

If mgl_does:have: return True the App will crash.

Sample code :

        NSExpression *expression = [NSExpression expressionForFunction:@"mgl_does:have:"
                                                             arguments:@[MGLConstantExpression(@{@"x": MGLConstantExpression(@0)}),
                                                                         MGLConstantExpression(@"x")]];

        BOOL b = [expression expressionValueWithObject:nil context:nil]; // crash here !!!
        b = true;

Does the NSExpression function "mgl_does:have" can use in this way? I think NSExpression function should return NSObject not BOOL.

Expected behavior

Not crash.

Actual behavior

Crash.

Screen Shot 2021-02-22 at 5 53 16 PM
1ec5 commented 2 years ago

I think NSExpression function should return NSObject not BOOL.

I think you’re right, this should be returning an NSValue containing a Boolean, not a raw Boolean:

https://github.com/mapbox/mapbox-gl-native-ios/blob/57b231776bb3bf95b90b61cee707cdb8bab33e1a/platform/darwin/src/NSExpression%2BMGLAdditions.mm#L206-L208