PromiseKit icon indicating copy to clipboard operation
PromiseKit copied to clipboard

XCode 9 Beta 4 - Issues with Void return Promises

Open wfilleman opened this issue 9 years ago • 16 comments

  • PromiseKit version: 4.2.2 swift4-beta1
  • Xcode version: 9 beta 4

When compiling this simple example to illustrate the issue, the compiler can't seem to understand the return Promise is of type Promise Void:

public func shouldReturnVoidPromise() -> Promise<Void> {
    return Promise { fulfill, reject in
        fulfill()
    }
}

The error message generated is: Cannot convert return expression of type 'Promise<(_, _) -> Void>' to return type 'Promise<Void>'

If I change this to:

public func shouldReturnVoidPromise() -> Promise<Bool> {
    return Promise { fulfill, reject in
        fulfill(true)
    }
}

Then no issues with the swift compiler.

I'm assuming this is a Swift compiler issue, although, I tried the August 1st Swift 4 snapshot and it still has the same issue. Is there a way to format this so that Swift 4 is happy? Or are we stuck waiting for a fix from the Swift team?

Thanks! Wes

wfilleman avatar Aug 03 '17 00:08 wfilleman

This is “tuplegate”, you can google it for more information. You may also want to let the Swift team know how awful it is for you so they are further incentivized to fix it before 4.0-gold.

Here's the current fix:

public func shouldReturnVoidPromise() -> Promise<Void> {
    return Promise { fulfill, reject in
        fulfill(())
    }
}

mxcl avatar Aug 03 '17 00:08 mxcl

Thanks mxcl! That explains other behavior I'm seeing in Swift 4 as well. For those reading, it appears the Swift team has announced that it's backing out of the change in Swift 4 that is causing this: https://lists.swift.org/pipermail/swift-evolution-announce/2017-June/000386.html

wfilleman avatar Aug 03 '17 13:08 wfilleman

I'm not sure this specific change is being backed-out.

mxcl avatar Aug 28 '17 22:08 mxcl

I'm late to the Swift 4 bandwagon, but just hit this same issue and spent the last 20 minutes sprinkling () in all my fulfill()s. Is there a specific location you'd recommend for us to communicate our displeasure to the Swift team at?

It sounds like most people think "tuple gate" has been resolved, but it sounds like this change at least hasn't been.

ryanschneider avatar Aug 30 '17 20:08 ryanschneider

https://twitter.com/slava_pestov on Twitter specifically told me it wasn't a bug and the fact it worked nicely before was the bug. Might be worth bugging him.

Otherwise you can report the bug to http://bugs.swift.org or make fuss on the swift-dev mailing list.

I agree it is lame.

mxcl avatar Aug 30 '17 23:08 mxcl

Still running into this problem on the Xcode 9 GM candidate so it seems that this has not been rolled back from Swift 4. Would it be possible to get the fix placed in a branch for Cocoapods users? It's feels dirty having to unlock the framework and make the change manually.

nalexander50 avatar Sep 16 '17 20:09 nalexander50

There is no fix…

Edit: do you mean you're having trouble compiling PromiseKit? If so you need to update. PromiseKit 4.4 has been compiling with Swift 3.2 and 4 for weeks now.

mxcl avatar Sep 16 '17 22:09 mxcl

Yeah, I’m getting a compilation error. I thought this was the same issue. I’ll create a new issue with details.

nalexander50 avatar Sep 16 '17 22:09 nalexander50

Leaving this open so people can find solutions. Will eventually close.

mxcl avatar Sep 16 '17 23:09 mxcl

@nalexander50 been waiting for your ticket, happy to help, if you open it.

mxcl avatar Sep 17 '17 02:09 mxcl

@mxcl, sorry about that. Sat down for dinner and this slipped my mind. It actually seems to have cleared itself up. Looking at the source code here on GitHub, I see the exact change that I had to make to force it to compile. I had added PromiseKit to my Podfile a while ago (couple months). I'm thinking that I was just working off of a cached version of the Pod without the Swift 4 fix. Thanks for the followup.

nalexander50 avatar Sep 17 '17 02:09 nalexander50

Did anyone filed a bug on bugs.swift.org? Couldn't find any.

Sega-Zero avatar Sep 18 '17 10:09 Sega-Zero

I'm definitely interested in progress on this. I see a path to PromiseKit 5, however those links don't go anywhere yet. I'm very anxious to get my app working on the iPhone X before it gets released, so the only way to do this is to be able to compile and run it, with its dependencies to PromiseKit in Xcode 9. I've been unsuccessful in any of my experiments to get this working either.

cvoisey avatar Sep 20 '17 22:09 cvoisey

@cvoisey please open a new ticket as what you are talking about doesn't seem related to this thread.

mxcl avatar Sep 20 '17 23:09 mxcl

I'm definitely interested in progress on this.

Like, there's nothing we can do about this. PromiseKit 4 compiles with Swift 3.0, 3.1, 3.2 and 4.0 with Xcode 8 and 9. After that you have to modify your code that uses promises as described above because this is what Swift 4 requires.

The other option is to stick with Swift 3.2, which Xcode 9 supports.

mxcl avatar Sep 20 '17 23:09 mxcl

Is there any more information about the issue? What I conclude after googling for a while is that we need to stick to fulfill(()). Ugly.

acecilia avatar Nov 07 '17 10:11 acecilia