Skip to content

Type mismatch in assignment is only detected in DEBUG build #9

@tempelmann

Description

@tempelmann

See this code in LuaExportMetaData.m:

- (void)setProperty:(const char*)propertyName toValue:(id)value onInstance:(id)instance {
    NSString *name = [NSString stringWithUTF8String:propertyName];
    LuaExportPropertyMetaData *metaData = exportedProperties[name];
    if( ! metaData || ! metaData->setter || metaData->readonly )
        return;
#if DEBUG
    if( value && metaData->type == _C_ID ) {
        Class valueClass = [value class];
        if( valueClass != metaData->objCType && ! [valueClass isSubclassOfClass:metaData->objCType] )
            [NSException raise:NSInvalidArgumentException format:@"object of type %@ can not be safely assigned to object of type %@", NSStringFromClass(valueClass), NSStringFromClass(metaData->objCType)];
    }
#endif
    setArgumentAt(metaData->setter, 0, metaData->propertySize, value, 2);
    [metaData->setter invokeWithTarget:instance];
}

The issue mentioned in #8 runs into the #if DEBUG section, where it then raises an exception - which is good because it's a user error that needs to be flagged as such.

However, if DEBUG is not set, then there'll be no exception raised, and the assignment goes through undetected, which is probably not good (and it'll trigger an assertion error "setting string to number succeeded" during unit testing).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions