Skip to content

5.10 compiler emits syntax error on code in #if(compiler>=6.0) block under specific conditions #79285

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

Open
gwynne opened this issue Feb 10, 2025 · 2 comments
Labels
assertion failure Bug → crash: An assertion failure bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. † libswiftSyntax Archive • Area → compiler: the once-integrated C++ Syntax library succeeded by SwiftSyntax parser Area → compiler: The legacy C++ parser

Comments

@gwynne
Copy link
Contributor

gwynne commented Feb 10, 2025

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
}
#endif

Expected 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
}
#endif

Environment

Swift version 5.10.1 (swift-5.10.1-RELEASE)
Target: x86_64-unknown-linux-gnu

Additional information

No response

@gwynne gwynne added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Feb 10, 2025
@MaxDesiatov MaxDesiatov added parser Area → compiler: The legacy C++ parser † libswiftSyntax Archive • Area → compiler: the once-integrated C++ Syntax library succeeded by SwiftSyntax assertion failure Bug → crash: An assertion failure and removed triage needed This issue needs more specific labels labels Feb 10, 2025
@shahmishal
Copy link
Member

Related GitHub Issue on why we are seeing assertion on release toolchain
#76091

@weissi
Copy link
Contributor

weissi commented Feb 11, 2025

AHC workaround by shuffling whitespace: swift-server/async-http-client#810

weissi added a commit to swift-server/async-http-client that referenced this issue Feb 11, 2025
Specifically Swift 5.10 _on Intel on Ubuntu Noble (24.04)_ has a crazy
bug which leads to compilation failures in a `#if compiler(>=6.0)`
block: swiftlang/swift#79285 .

This workaround fixes the compilation by _changing the whitespace_.

Thanks @gwynne for finding this workaround!

---------

Co-authored-by: Johannes Weiss <johannes@jweiss.io>
FranzBusch added a commit to apple/swift-metrics that referenced this issue Mar 18, 2025
Specifically Swift 5.10 on Intel on Ubuntu Noble (24.04) has a crazy bug which leads to compilation failures in a #if compiler(>=6.0) block: swiftlang/swift#79285 .

This workaround fixes the compilation by changing the whitespace.
FranzBusch added a commit to apple/swift-metrics that referenced this issue Mar 18, 2025
Specifically Swift 5.10 on Intel on Ubuntu Noble (24.04) has a crazy bug which leads to compilation failures in a #if compiler(>=6.0) block: swiftlang/swift#79285 .

This workaround fixes the compilation by changing the whitespace.
czechboy0 pushed a commit to apple/swift-metrics that referenced this issue Mar 18, 2025
Specifically Swift 5.10 on Intel on Ubuntu Noble (24.04) has a crazy bug
which leads to compilation failures in a #if compiler(>=6.0) block:
swiftlang/swift#79285 .

This workaround fixes the compilation by changing the whitespace.

Fixes #166
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assertion failure Bug → crash: An assertion failure bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. † libswiftSyntax Archive • Area → compiler: the once-integrated C++ Syntax library succeeded by SwiftSyntax parser Area → compiler: The legacy C++ parser
Projects
None yet
Development

No branches or pull requests

4 participants