Skip to content

Commit 70d02d0

Browse files
committed
[Concurrency] @preconcurrency warnings should only come back when the imported
module has enabled Swift 6. Warnings when the client enables Swift 6 are not useful because that's not the point when the library API has been audited.
1 parent 0655578 commit 70d02d0

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,9 @@ DiagnosticBehavior SendableCheckContext::diagnosticBehavior(
882882
if (sourceFile)
883883
sourceFile->setImportUsedPreconcurrency(*import);
884884

885-
return nominal->getASTContext().LangOpts.isSwiftVersionAtLeast(6)
885+
// `@preconcurrency` suppresses diagnostics until the imported
886+
// module enables Swift 6.
887+
return import->module.importedModule->isConcurrencyChecked()
886888
? DiagnosticBehavior::Warning
887889
: DiagnosticBehavior::Ignore;
888890
}

test/ClangImporter/predates_concurrency_import_swift6.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
func acceptSendable<T: Sendable>(_: T) { }
1313

1414
func useSendable(ns: NSString) {
15-
// Note: warning below is downgraded due to @preconcurrency
16-
acceptSendable(ns) // expected-warning{{type 'NSString' does not conform to the 'Sendable' protocol}}
15+
// Note: warning below is suppressed due to @preconcurrency
16+
acceptSendable(ns)
1717
}

test/Concurrency/predates_concurrency_import_swift6.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/StrictModule.swiftmodule -module-name StrictModule -strict-concurrency=complete %S/Inputs/StrictModule.swift
2+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/StrictModule.swiftmodule -module-name StrictModule -swift-version 6 %S/Inputs/StrictModule.swift
33
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/NonStrictModule.swiftmodule -module-name NonStrictModule %S/Inputs/NonStrictModule.swift
44

55
// RUN: %target-swift-frontend -swift-version 6 -I %t %s %s -emit-sil -o /dev/null -verify
@@ -15,5 +15,5 @@ func acceptSendable<T: Sendable>(_: T) { }
1515
@available(SwiftStdlib 5.1, *)
1616
func test(ss: StrictStruct, ns: NonStrictClass) {
1717
acceptSendable(ss) // expected-warning{{type 'StrictStruct' does not conform to the 'Sendable' protocol}}
18-
acceptSendable(ns) // expected-warning{{type 'NonStrictClass' does not conform to the 'Sendable' protocol}}
18+
acceptSendable(ns)
1919
}

0 commit comments

Comments
 (0)