Skip to content

Fix build failure when building with pre-6.2 toolchain due to unrecognized unsafe keyword #1093

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Sources/TestingMacros/Support/EffectfulExpressionHandling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ func applyEffectfulKeywords(_ effectfulKeywords: Set<Keyword>, to expr: some Exp

let needAwait = effectfulKeywords.contains(.await) && !expr.is(AwaitExprSyntax.self)
let needTry = effectfulKeywords.contains(.try) && !expr.is(TryExprSyntax.self)

// The 'unsafe' keyword was introduced in 6.2 as part of SE-0458. Older
// toolchains are not aware of it, so avoid emitting expressions involving
// that keyword when the macro has been built using an older toolchain.
#if compiler(>=6.2)
let needUnsafe = effectfulKeywords.contains(.unsafe) && !expr.is(UnsafeExprSyntax.self)
#endif

// First, add thunk function calls.
if needAwait {
Expand All @@ -120,9 +126,11 @@ func applyEffectfulKeywords(_ effectfulKeywords: Set<Keyword>, to expr: some Exp
if needTry {
expr = _makeCallToEffectfulThunk(.identifier("__requiringTry"), passing: expr)
}
#if compiler(>=6.2)
if needUnsafe {
expr = _makeCallToEffectfulThunk(.identifier("__requiringUnsafe"), passing: expr)
}
#endif

// Then add keyword expressions. (We do this separately so we end up writing
// `try await __r(__r(self))` instead of `try __r(await __r(self))` which is
Expand All @@ -143,6 +151,7 @@ func applyEffectfulKeywords(_ effectfulKeywords: Set<Keyword>, to expr: some Exp
)
)
}
#if compiler(>=6.2)
if needUnsafe {
expr = ExprSyntax(
UnsafeExprSyntax(
Expand All @@ -151,6 +160,7 @@ func applyEffectfulKeywords(_ effectfulKeywords: Set<Keyword>, to expr: some Exp
)
)
}
#endif

expr.leadingTrivia = originalExpr.leadingTrivia
expr.trailingTrivia = originalExpr.trailingTrivia
Expand Down