-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Description
Description
When run in the swift:5.10-noble Docker image for x86_64, the compiler emits a nonsensical syntax error for code enclosed in a #if compiler(>=6.0) block which uses sending in a specific way (see reproduction below). The complete compiler output for the given repro is:
test.swift:4:1: error: extraneous code at top level
) async throws -> sending R {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.swift:1:1: error: new Swift parser generated errors for code that C++ parser accepted
#if compiler(>=6.0)
^
error: fatalError
This issue does not occur if run on any other OS (including any other version of Ubuntu), nor does it appear to occur on arm64, even in Noble.
This bug appears when using the 5.10.1-RELEASE compiler on x86_64 Ubuntu Noble (24.04) to build AsyncHTTPClient as of the 1.25.0 release, in the file StructuredConcurrencyHelpers.swift. See also async-http-client#809.
Reproduction
#if compiler(>=6.0)
func f<R>(
_ body: () async throws -> sending R
) async throws -> sending R {
let r = try await body()
return r
}
#endifExpected behavior
This code should compile as written.
It is worth noting that even a trivial modification of whitespace is sufficient to eliminate the build failure. For example, this version of the same code (a single newline has been removed) builds correctly:
#if compiler(>=6.0)
func f<R>( _ body: () async throws -> sending R
) async throws -> sending R {
let r = try await body()
return r
}
#endifEnvironment
Swift version 5.10.1 (swift-5.10.1-RELEASE)
Target: x86_64-unknown-linux-gnu
Additional information
No response