Skip to content

Commit 5e17762

Browse files
authored
Merge pull request #82173 from xedin/rdar-152687353
[Concurrency] NonisolatedNonsendingByDefault: Migration applies only to the current module declarations
2 parents 9259c3e + 1457aec commit 5e17762

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

lib/Sema/NonisolatedNonsendingByDefaultMigration.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ void NonisolatedNonsendingByDefaultMigrationTarget::diagnose() const {
153153

154154
const auto featureName = feature.getName();
155155
if (decl) {
156+
// Only diagnose declarations from the current module.
157+
if (decl->getModuleContext() != ctx.MainModule)
158+
return;
159+
156160
// Diagnose the function, but slap the attribute on the storage declaration
157161
// instead if the function is an accessor.
158162
auto *functionDecl = dyn_cast<AbstractFunctionDecl>(decl);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %empty-directory(%t/src)
2+
// RUN: split-file %s %t/src
3+
4+
/// Build the library
5+
// RUN: %target-swift-frontend -emit-module %t/src/Lib.swift \
6+
// RUN: -target %target-swift-5.1-abi-triple \
7+
// RUN: -module-name Lib -swift-version 5 -enable-library-evolution \
8+
// RUN: -emit-module-path %t/Lib.swiftmodule \
9+
// RUN: -emit-module-interface-path %t/Lib.swiftinterface
10+
11+
// RUN: rm %t/Lib.swiftmodule
12+
13+
// Build the client using interface
14+
// RUN: %target-swift-frontend -typecheck -verify -target %target-swift-5.1-abi-triple -swift-version 5 -I %t %t/src/Test.swift -enable-upcoming-feature NonisolatedNonsendingByDefault:migrate
15+
16+
// REQUIRES: asserts
17+
// REQUIRES: swift_feature_NonisolatedNonsendingByDefault
18+
19+
//--- Lib.swift
20+
public struct Counter: AsyncSequence {
21+
public typealias Element = Int
22+
23+
public init(howHigh: Int) {
24+
}
25+
26+
public struct AsyncIterator: AsyncIteratorProtocol {
27+
public mutating func next() async -> Int? {
28+
nil
29+
}
30+
}
31+
32+
public func makeAsyncIterator() -> AsyncIterator {
33+
AsyncIterator()
34+
}
35+
}
36+
37+
//--- Test.swift
38+
import Lib
39+
40+
func count(n: Int) async {
41+
// expected-warning@-1 {{feature 'NonisolatedNonsendingByDefault' will cause nonisolated async global function 'count' to run on the caller's actor; use '@concurrent' to preserve behavior}}
42+
for await _ in Counter(howHigh: n) {
43+
}
44+
}

0 commit comments

Comments
 (0)