Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it illegal to construct AnyPromise() in Swift without arguments #1175

Closed
jfahrenkrug opened this issue Nov 20, 2020 · 0 comments · Fixed by #1211
Closed

Make it illegal to construct AnyPromise() in Swift without arguments #1175

jfahrenkrug opened this issue Nov 20, 2020 · 0 comments · Fixed by #1211

Comments

@jfahrenkrug
Copy link
Contributor

  • PromiseKit 6.13.1, installed via CocoaPods

I recently ran into a nasty crashing bug in my codebase because I had a return AnyPromise() in some edge case. I wasn't aware that it was illegal to construct AnyPromise() without any arguments.

AnyPromise's default argument-less init initializer is correctly marked as unavailable in the Objective-C header (see https://github.com/mxcl/PromiseKit/blob/master/Sources/AnyPromise.h#L295).
When trying to call it from Objective-C with [[AnyPromise alloc] init] the compiler correctly complains. However, there's no warning and no compiler error when illegally constructing it from Swift using AnyPromise(). Is there a way to work around for this? I've tried a few, but to no avail. Shouldn't the Swift compiler pick up the Objective-C unavailable declaration in AnyPromise.h? So is there any solution we could implement for this?

Here's a related discussion with an Apple Engineer: https://developer.apple.com/forums/thread/650054?login=true&page=1#648364022

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 a pull request may close this issue.

1 participant