From d82b0b7caf469b68ae53ebbb5db34fb382f2efd4 Mon Sep 17 00:00:00 2001 From: Julian Rex Date: Sat, 13 Apr 2019 13:13:30 -0400 Subject: [ios] Fix analyzer fix --- platform/darwin/src/NSExpression+MGLAdditions.h | 2 +- platform/darwin/src/NSExpression+MGLAdditions.mm | 35 +++++++++++------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/platform/darwin/src/NSExpression+MGLAdditions.h b/platform/darwin/src/NSExpression+MGLAdditions.h index a19ec1af2e..9ef6623068 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.h +++ b/platform/darwin/src/NSExpression+MGLAdditions.h @@ -190,7 +190,7 @@ FOUNDATION_EXTERN MGL_EXPORT const MGLExpressionInterpolationMode MGLExpressionI @return An initialized expression equivalent to `object`, suitable for use as the value of a style layer attribute. */ -+ (instancetype)expressionWithMGLJSONObject:(id)object NS_SWIFT_NAME(init(mglJSONObject:)); ++ (instancetype)expressionWithMGLJSONObject:(nullable id)object NS_SWIFT_NAME(init(mglJSONObject:)); /** An equivalent Foundation object that can be serialized as JSON. diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index fe2e5a0a31..026d8bec02 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -792,24 +792,19 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { } else if ([curveType isEqualToString:@"cubic-bezier"]) { curveParameters = @[@"literal", [interpolationOptions subarrayWithRange:NSMakeRange(1, 4)]]; } - - NSAssert(curveParameters, @"curveParameters should be non-nil"); - if (curveParameters) { - NSExpression *curveParameterExpression = [NSExpression expressionWithMGLJSONObject:curveParameters]; - argumentObjects = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)]; - NSExpression *inputExpression = [NSExpression expressionWithMGLJSONObject:argumentObjects.firstObject]; - NSArray *stopExpressions = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)]; - NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:stopExpressions.count / 2]; - NSEnumerator *stopEnumerator = stopExpressions.objectEnumerator; - while (NSNumber *key = stopEnumerator.nextObject) { - NSExpression *valueExpression = stopEnumerator.nextObject; - stops[key] = [NSExpression expressionWithMGLJSONObject:valueExpression]; - } - NSExpression *stopExpression = [NSExpression expressionForConstantValue:stops]; - return [NSExpression expressionForFunction:@"mgl_interpolate:withCurveType:parameters:stops:" - arguments:@[inputExpression, curveTypeExpression, curveParameterExpression, stopExpression]]; + NSExpression *curveParameterExpression = [NSExpression expressionWithMGLJSONObject:curveParameters]; + argumentObjects = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)]; + NSExpression *inputExpression = [NSExpression expressionWithMGLJSONObject:argumentObjects.firstObject]; + NSArray *stopExpressions = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)]; + NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:stopExpressions.count / 2]; + NSEnumerator *stopEnumerator = stopExpressions.objectEnumerator; + while (NSNumber *key = stopEnumerator.nextObject) { + NSExpression *valueExpression = stopEnumerator.nextObject; + stops[key] = [NSExpression expressionWithMGLJSONObject:valueExpression]; } - + NSExpression *stopExpression = [NSExpression expressionForConstantValue:stops]; + return [NSExpression expressionForFunction:@"mgl_interpolate:withCurveType:parameters:stops:" + arguments:@[inputExpression, curveTypeExpression, curveParameterExpression, stopExpression]]; } else if ([op isEqualToString:@"step"]) { NSExpression *inputExpression = [NSExpression expressionWithMGLJSONObject:argumentObjects[0]]; NSArray *stopExpressions = [argumentObjects subarrayWithRange:NSMakeRange(1, argumentObjects.count - 1)]; @@ -1031,7 +1026,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { } case NSKeyPathExpressionType: { - NSArray *expressionObject = @[]; + NSArray *expressionObject; NSArray *keyPath = [self.keyPath componentsSeparatedByString:@"."]; for (NSString *pathComponent in keyPath) { if (expressionObject) { @@ -1042,7 +1037,9 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { } NSAssert(expressionObject.count > 0, @"expressionObject should be non-empty"); - return expressionObject; + + // Return a non-null value to quieten static analysis + return expressionObject ?: @[]; } case NSFunctionExpressionType: { -- cgit v1.2.1