Skip to content

Commit ed4e7d5

Browse files
committed
[Concurrency] Downgrade @preconcurrency @Sendable conversion failures
to warnings even in Swift 6.
1 parent 2c3fb16 commit ed4e7d5

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/Sema/CSFix.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,16 @@ getConcurrencyFixBehavior(ConstraintSystem &cs, ConstraintKind constraintKind,
294294

295295
// For a @preconcurrency callee outside of a strict concurrency
296296
// context, ignore.
297-
if (cs.hasPreconcurrencyCallee(locator) &&
298-
!contextRequiresStrictConcurrencyChecking(
299-
cs.DC, GetClosureType{cs}, ClosureIsolatedByPreconcurrency{cs}))
297+
if (cs.hasPreconcurrencyCallee(locator)) {
298+
// Preconcurrency failures are always downgraded to warnings, even in
299+
// Swift 6 mode.
300+
if (contextRequiresStrictConcurrencyChecking(
301+
cs.DC, GetClosureType{cs}, ClosureIsolatedByPreconcurrency{cs})) {
302+
return FixBehavior::DowngradeToWarning;
303+
}
304+
300305
return FixBehavior::Suppress;
306+
}
301307

302308
// Otherwise, warn until Swift 6.
303309
if (!cs.getASTContext().LangOpts.isSwiftVersionAtLeast(6))

test/Concurrency/predates_concurrency_swift6.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,14 @@ do {
180180
}
181181
}
182182
}
183+
184+
185+
186+
@preconcurrency
187+
func withSendableClosure(_: @Sendable () -> Void) {}
188+
189+
func conversionDowngrade() {
190+
let ns: () -> Void = {}
191+
withSendableClosure(ns)
192+
// expected-warning@-1 {{converting non-sendable function value to '@Sendable () -> Void' may introduce data races}}
193+
}

0 commit comments

Comments
 (0)