Skip to content

Commit c17d370

Browse files
authored
Merge pull request #82219 from xedin/rdar-152687353-6.2
[6.2][Concurrency] NonisolatedNonsendingByDefault: Migration applies only to the current module declarations
2 parents a2bd6ca + c0984d2 commit c17d370

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

lib/Sema/NonisolatedNonsendingByDefaultMigration.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ void NonisolatedNonsendingByDefaultMigrationTarget::diagnose() const {
7373
return;
7474
}
7575

76+
// Only diagnose declarations from the current module.
77+
if (decl->getModuleContext() != ctx.MainModule) {
78+
return;
79+
}
80+
7681
// If the attribute cannot appear on this kind of declaration, we can't
7782
// diagnose it.
7883
if (!DeclAttribute::canAttributeAppearOnDecl(DeclAttrKind::Concurrent,
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)