Skip to content

Conversation

@rcancro
Copy link

@rcancro rcancro commented Sep 9, 2024

  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 by comparing its objCType to the result of @encode(BOOL):
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 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 to compare the objCType of value with the objCType of a NSNumber we know is created with a BOOL:

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.

@rcancro rcancro force-pushed the build branch 2 times, most recently from 10bc98a to ca6dbe1 Compare September 9, 2024 20:48
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.
chenrui333 added a commit to Homebrew/formula-patches that referenced this pull request Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant