Skip to content

Spurious warnings about noasync calls in #expect(throws:) #1177

Closed
@grynspan

Description

@grynspan

Given the following test function:

@available(*, noasync)
func f() {}

@Test func g() {
  #expect(throws: (any Error).self) {
    f()
  }
}

In Swift 6.2 the compiler emits a warning due to improved typechecking during macro expansion:

⚠️ function 'f' is unavailable from asynchronous contexts; this will be an error in a future Swift language mode

Because the compiler is now inferring the type of the closure passed to #expect(throws:) as async before macro expansion rather than inferring its type (as non-async) after.

Metadata

Metadata

Assignees

Labels

bug🪲 Something isn't workingconcurrency🔀 Swift concurrency/sendability issuesmacros🔭 Related to Swift macros such as @Test or #expectpublic-apiAffects public API

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions