Skip to content

Commit ca6dbe1

Browse files
committed
Fix build issues
1. When running `make build` the compiler complains that it “can’t type check this expression in reasonable time” in `ObjectiveCInitExtension.swift`. I put the expression in an explicitly declared variable to help out the compiler’s tiny brain. 2. The test `testPolymorphicPropWithBool` is failing. Looking at the code, we test that an `NSNumber` is a bool via: ``` if ([value isKindOfClass:[NSNumber class]] && strcmp([value objCType], @encode(BOOL)) == 0) { self->_polymorphicProp = [EverythingPolymorphicProp objectWithBoolean:[value boolValue] & 0x1]; } ``` However, I’m seeing weird behavior where `@encode(BOOL)` is not returning `c` as [Apple documentation](https://developer.apple.com/documentation/objectivec/bool) says it should: ``` BOOL is explicitly signed so @encode(BOOL) is c rather than C even if -funsigned-char is used. ``` Here is what I was seeing in the debugger: ``` (lldb) po @encode(BOOL) "B" (lldb) po [@yES objCType] "c" (lldb) po [@no objCType] "c" ``` I am not sure why this is retuning `B`, but it seems a safer check would be: ``` if ([value isKindOfClass:[NSNumber class]] && strcmp([value objCType], [[NSNumber numberWithBool:0] objCType]) == 0) { self->_polymorphicProp = [EverythingPolymorphicProp objectWithBoolean:[value boolValue] & 0x1]; } ``` I added this change to fix the tests.
1 parent a2fe6e1 commit ca6dbe1

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
name: Run Unit and Integration Tests (macOS)
1515
runs-on: macOS-latest
1616
steps:
17+
- name: Install dependencies
18+
run: python -m pip install --upgrade pip looseversion
1719
- name: Checkout the Git repository
1820
uses: actions/checkout@v1
1921
- run: make ci_tests

Sources/Core/ObjectiveCInitExtension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ extension ObjCModelRenderer {
272272
}
273273

274274
case .boolean:
275-
return ObjCIR.ifStmt("[\(rawObjectName) isKindOfClass:[NSNumber class]] && strcmp([\(rawObjectName) objCType], @encode(BOOL)) == 0") {
275+
return ObjCIR.ifStmt("[\(rawObjectName) isKindOfClass:[NSNumber class]] && strcmp([\(rawObjectName) objCType], [[NSNumber numberWithBool:0] objCType]) == 0") {
276276
transformToADTInit(renderPropertyInit(propertyToAssign, rawObjectName, keyPath: keyPath, schema: schema, firstName: firstName, counter: counter, dirtyPropertyName: dirtyPropertyName, needsTypeCheck: false))
277277
}
278278
case .array(itemType: _):

Sources/Core/ObjectiveCNSCodingExtension.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Foundation
1111
extension ObjCModelRenderer {
1212
func renderInitWithCoder() -> ObjCIR.Method {
1313
return ObjCIR.method("- (instancetype)initWithCoder:(NSCoder *)aDecoder") {
14-
[
14+
let body: [String] = [
1515
self.isBaseClass ? ObjCIR.ifStmt("!(self = [super init])") { ["return self;"] } :
1616
"if (!(self = [super initWithCoder:aDecoder])) { return self; }",
1717
self.properties.filter { (_, schema) -> Bool in
@@ -35,6 +35,7 @@ extension ObjCModelRenderer {
3535
},
3636
"return self;",
3737
]
38+
return body
3839
}
3940
}
4041

0 commit comments

Comments
 (0)