Key Value Coding Compliance For C Unions

Originator:russfenenga
Number:rdar://50830331 Date Originated:5/15/19
Status:Open Resolved:
Product:Foundation Product Version:12.3
Classification:Bug Reproducible:Every time
 
Summary:
The C data type Union is not key value coding compliant.  Attempting to call setValue:ForKey: will crash and give the error "failed: caught "NSUnknownKeyException", "[<DUXOSBindClass 0x6000008258c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key testUnion.""

Steps to Reproduce:
The steps to reproduce just require attempting to call setValue:ForKey:  with a Union encoded into an NSValue.

typedef struct {
    CGFloat testFloat;
} DUXOSTestStruct;

typedef union {
    CGFloat testFloat;
} DUXOSTestUnion;


@interface DUXOSBindClass : NSObject

@property (assign, nonatomic) DUXOSTestStruct testStruct;
@property (assign, nonatomic) DUXOSTestUnion testUnion;

@end

@implementation DUXOSBindClass

- (instancetype)init {
    self = [super init];
    if (self) {
        DUXOSTestStruct exampleStruct = {0.0};
        self.testStruct = exampleStruct;
        
        DUXOSTestUnion exampleUnion = {0.0};
        self.testUnion = exampleUnion;
    }
    return self;
}

@end

@interface DUXOSRuntimeMappingCTests : XCTestCase

@property (strong, nonatomic) DUXOSBindClass *bindClass;

@end

@implementation DUXOSRuntimeMappingCTests

- (void)setUp {
    // Put setup code here. This method is called before the invocation of each test method in the class.
    self.bindClass = [DUXOSBindClass new];
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    self.bindClass = nil;
}

- (void)testStruct {
    DUXOSTestStruct testStruct = {1.0};
    [self.bindClass setValue:[NSValue value:&testStruct withObjCType:@encode(DUXOSTestStruct)] forKey:@"testStruct"];
    XCTAssert(self.bindClass.testStruct.testFloat == 1.0);
}

- (void)testUnion {
    DUXOSTestUnion testUnion = {1.0};
    [self.bindClass setValue:[NSValue value:&testUnion withObjCType:@encode(DUXOSTestUnion)] forKey:@"testUnion"];
    XCTAssert(self.bindClass.testUnion.testFloat == 1.0);
}

@end


Expected Results:

The test for both the struct and the union should pass.

Actual Results:
The test for the struct passes but the test for the union crashes with error "failed: caught "NSUnknownKeyException", "[<DUXOSBindClass 0x6000008258c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key testUnion.""

Version/Build:
Xcode 10.2.1 /12.3

Configuration:
iOS 12.3 iPad Pro 12.9-inch 3rd generation simulator

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!