Skip to content

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

Description

@jfahrenkrug
  • 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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