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

[SR-15049] async let and @rethrows protocol functions don't work together #57376

Closed
adam-fowler opened this issue Aug 10, 2021 · 6 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. concurrency Feature: umbrella label for concurrency language features

Comments

@adam-fowler
Copy link

Previous ID SR-15049
Radar rdar://problem/81787316
Original Reporter @adam-fowler
Type Bug
Status Reopened
Resolution
Environment

Using Xcode V13 beta 4

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: c534d42e41bdbf13e3d2e82e17ba9ad5

Issue Description:

The following code generates the compile error "Call can throw, but it is executed in a non-throwing autoclosure".

func testAsyncSequence<Seq: AsyncSequence>(_ seq: Seq) async throws where Seq.Element == Int {
    async let result: Int = seq.reduce(0) { $0 + $1 }
    try await print(result)
}

This appears to be caused by `AsyncSequence.reduce` being tagged rethrows. If you change it to throws there is no compile error. Shouldn't the async let also work for functions tagged as rethrows?

I have managed to reduce the issue down to the following. With the following protocol and struct

@rethrows protocol TestRethrowProtocol {
    func fn() async throws
}
extension TestRethrowProtocol {
    func testRethrow() async rethrows {
        try await self.fn()
    }
}

struct TestRethrowStruct: TestRethrowProtocol {
    func fn() async throws {}
}

The following code will generate the error "Call can throw, but it is executed in a non-throwing autoclosure".

let s = TestRethrowStruct()
async let rt: () = s.testRethrow()
try await rt
@typesanitizer
Copy link

The diagnostic seems quite confusing, so we should improve that because there is no autoclosure (unless I am missing something?).

But the rethrows is intentional as you saw in https://bugs.swift.org/browse/SR-14423

@typesanitizer
Copy link

I filed https://bugs.swift.org/browse/SR-15052 for improving the diagnostics in this area.

@adam-fowler
Copy link
Author

theindigamer (JIRA User) I'm not arguing for reduce to be tagged throws. I'd have thought the "async let" should work regardless of whether the function is throws or rethrows. Edited main text to make this clearer.

@ktoso
Copy link
Member

ktoso commented Aug 11, 2021

Thanks for the more detailed reproducer, this seems like in issue by itself indeed. Thanks, Adam.
@swift-ci create

@typesanitizer
Copy link

Sorry, I misunderstood the original JIRA. Thanks for re-opening Konrad.

@LucianoPAlmeida
Copy link
Collaborator

Resolved on main and test case added in #61175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. concurrency Feature: umbrella label for concurrency language features
Projects
None yet
Development

No branches or pull requests

5 participants