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

Async/Await Support: 'async' call in an autoclosure that does not support concurrency #1035

Closed
1 task done
lasseporsch opened this issue Mar 20, 2023 · 3 comments
Closed
1 task done

Comments

@lasseporsch
Copy link

  • I have read CONTRIBUTING and have done my best to follow them.

What did you do?

Following the Documentation, I wanted to write a Quickspec that tests an async function.
I've boiled it down to this minimal reproducible example:

import Quick
import Nimble

struct Foo {
    func bar() async -> String {
        await Task { "Hello World" }.value
    }
}

final class FooSpec: QuickSpec {
    override func spec() {
        describe("A Foo") {
            describe("When calling Bar") {
                var foo: Foo!
                beforeEach {
                    foo = Foo()
                }
                it("Says Hello World") {
                    await expect(await foo.bar()).to(equal("Hello World"))
                }
            }
        }
    }
}

The documentation says that when using Quick, there's no need to do anything to provide an async context - so I didn't.

What did you expect to happen?

I expected this to work as in the documentation.

What actually happened instead?

The code does not compile:
image

However, adding an additional pair of curly brackets fixes the build error:

it("Says Hello World") { 
//  await expect(await foo.bar()).to(equal("Hello World"))    // Does not compile
    await expect({ await foo.bar() }) == "Hello World"        // Does compile
}

So I guess either the async versions of expect should be corrected to match the documentation or the other way around.

Environment

List the software versions you're using:

  • Quick: 6.1.0
  • Nimble: 11.2.1
  • Xcode Version: 14.2 (14C18)
  • Swift Version: Xcode Default

Please also mention which package manager you used and its version. Delete the
other package managers in this list:

  • Swift Package Manager 5.7.1

Project that demonstrates the issue

See the code example above.

@younata
Copy link
Member

younata commented Mar 27, 2023

This is intentional.

use await expect { await foo.bar() } == "Hello World" instead. expect with async closures does not have a version that uses autoclosures (the compiler would always assume you want the autoclosure is async, and thus raise compiler errors if you use Nimble in a synchronous context - I don't know if this has since been fixed).

@younata younata closed this as not planned Won't fix, can't repro, duplicate, stale Mar 27, 2023
@lasseporsch
Copy link
Author

@younata: I understand. I'd suggest fixing the documentation then. Here the syntax with the round brackets is still used.

@younata
Copy link
Member

younata commented Mar 28, 2023

Whoops. Sorry about the confusion. The documentation is fixed now.

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

No branches or pull requests

2 participants