mapbox/mapbox-gl-native-ios

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

alanchenboy opened this issue · 1 comments

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

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:

- (BOOL)mgl_does:(id)object have:(NSString *)key {
return [object valueForKey:key] != nil;
}