Skip to content

Commit 813f952

Browse files
committed
[Concurrency] Suppress concurrency diagnostics in extensions of preconcurrency
declarations if strict checking is not enabled.
1 parent 6212085 commit 813f952

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5093,7 +5093,8 @@ bool swift::contextRequiresStrictConcurrencyChecking(
50935093
// features.
50945094
if (auto *extension = dyn_cast<ExtensionDecl>(decl)) {
50955095
auto *nominal = extension->getExtendedNominal();
5096-
if (nominal && hasExplicitIsolationAttribute(nominal))
5096+
if (nominal && hasExplicitIsolationAttribute(nominal) &&
5097+
!getActorIsolation(nominal).preconcurrency())
50975098
return true;
50985099
}
50995100

test/Concurrency/predates_concurrency.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,29 @@ nonisolated func blah() {
219219
InferMainActorPreconcurrency.predatesConcurrency()
220220
// expected-warning@-1 {{call to main actor-isolated static method 'predatesConcurrency()' in a synchronous nonisolated context}}
221221
}
222+
223+
protocol NotIsolated {
224+
func requirement()
225+
// expected-complete-tns-note@-1 {{mark the protocol requirement 'requirement()' 'async' to allow actor-isolated conformances}}
226+
}
227+
228+
extension MainActorPreconcurrency: NotIsolated {
229+
func requirement() {}
230+
// expected-complete-tns-warning@-1 {{main actor-isolated instance method 'requirement()' cannot be used to satisfy nonisolated protocol requirement}}
231+
// expected-complete-tns-note@-2 {{add 'nonisolated' to 'requirement()' to make this instance method not isolated to the actor}}
232+
// expected-complete-tns-note@-3 {{calls to instance method 'requirement()' from outside of its actor context are implicitly asynchronous}}
233+
234+
235+
class Nested {
236+
weak var c: MainActorPreconcurrency?
237+
238+
func test() {
239+
// expected-complete-tns-note@-1 {{add '@MainActor' to make instance method 'test()' part of global actor 'MainActor'}}
240+
241+
if let c {
242+
c.requirement()
243+
// expected-complete-tns-warning@-1 {{call to main actor-isolated instance method 'requirement()' in a synchronous nonisolated context}}
244+
}
245+
}
246+
}
247+
}

0 commit comments

Comments
 (0)