Skip to content

Compilation error: expected expression after 'unsafe' #81323

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

Closed
vsarunas opened this issue May 6, 2025 · 0 comments · Fixed by #81429
Closed

Compilation error: expected expression after 'unsafe' #81323

vsarunas opened this issue May 6, 2025 · 0 comments · Fixed by #81429
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@vsarunas
Copy link

vsarunas commented May 6, 2025

Description

6.1 is able to compile the code below, but it does not compile in swift-6.2-DEVELOPMENT-SNAPSHOT-2025-04-24-a nor in swift-DEVELOPMENT-SNAPSHOT-2025-04-30-a

swiftc unsafe.swift
unsafe.swift:2:18: error: expected expression after 'unsafe'
1 | func unsafeWork(_ unsafe: Bool) -> Int {
2 |    return unsafe ? 0 : 1
  |                  `- error: expected expression after 'unsafe'
3 | }
4 | print(unsafeWork(true))

Worked around this by escaping `unsafe`.

Reproduction

func unsafeWork() -> Int {
   let unsafe: Bool = true
   return unsafe ? 0 : 1
   // this works:
   // return if unsafe { 0 } else { 1 }
}
print(unsafeWork())

Expected behavior

To compile

Environment

swiftc -v
Apple Swift version 6.2-dev (LLVM 81ab6d9f7e4810f, Swift 9cc1947)
Target: arm64-apple-macosx15.0

swiftc --version
Swift version 6.2-dev (LLVM 978186dad468cc4, Swift 2d7b7a7)
Target: x86_64-unknown-linux-gnu
Build config: +assertions

Additional information

No response

@vsarunas vsarunas added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels May 6, 2025
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. triage needed This issue needs more specific labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant