Skip to content

Commit b5198c4

Browse files
committed
[Concurrency] Downgrade @preconcurrency @Sendable conversion failures
to warnings even in Swift 6. (cherry picked from commit a31a9d3)
1 parent f88d8a4 commit b5198c4

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
@@ -269,10 +269,16 @@ getConcurrencyFixBehavior(ConstraintSystem &cs, ConstraintKind constraintKind,
269269

270270
// For a @preconcurrency callee outside of a strict concurrency
271271
// context, ignore.
272-
if (cs.hasPreconcurrencyCallee(locator) &&
273-
!contextRequiresStrictConcurrencyChecking(
274-
cs.DC, GetClosureType{cs}, ClosureIsolatedByPreconcurrency{cs}))
272+
if (cs.hasPreconcurrencyCallee(locator)) {
273+
// Preconcurrency failures are always downgraded to warnings, even in
274+
// Swift 6 mode.
275+
if (contextRequiresStrictConcurrencyChecking(
276+
cs.DC, GetClosureType{cs}, ClosureIsolatedByPreconcurrency{cs})) {
277+
return FixBehavior::DowngradeToWarning;
278+
}
279+
275280
return FixBehavior::Suppress;
281+
}
276282

277283
// Otherwise, warn until Swift 6.
278284
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
@@ -162,3 +162,14 @@ do {
162162
}
163163
}
164164
}
165+
166+
167+
168+
@preconcurrency
169+
func withSendableClosure(_: @Sendable () -> Void) {}
170+
171+
func conversionDowngrade() {
172+
let ns: () -> Void = {}
173+
withSendableClosure(ns)
174+
// expected-warning@-1 {{converting non-sendable function value to '@Sendable () -> Void' may introduce data races}}
175+
}

0 commit comments

Comments
 (0)