Skip to content

Commit d6c8812

Browse files
committed
Add tests for SendableProhibitsMainActorInference
1 parent ee9f6f8 commit d6c8812

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-frontend -swift-version 5 -emit-sil -default-isolation MainActor %s -verify -verify-additional-prefix swift5- -enable-experimental-feature SendableProhibitsMainActorInference
2+
// RUN: %target-swift-frontend -swift-version 6 -emit-sil -default-isolation MainActor %s -verify -verify-additional-prefix swift6- -enable-experimental-feature SendableProhibitsMainActorInference
3+
4+
// REQUIRES: swift_feature_SendableProhibitsMainActorInference
5+
6+
// Ensure that a Sendable-conforming protocol suppresses @MainActor inference
7+
// for a type.
8+
enum CK: CodingKey {
9+
case one
10+
11+
func f() { }
12+
}
13+
14+
nonisolated func testCK(x: CK) {
15+
x.f() // okay, because CK and CK.f are not @MainActor.
16+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// REQUIRES: swift_swift_parser, executable_test
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath
5+
6+
// Check for errors
7+
// RUN: %target-swift-frontend -swift-version 5 -typecheck -load-plugin-library %t/%target-library-name(MacroDefinition) %s -I %t -disable-availability-checking -swift-version 6 -default-isolation MainActor -enable-experimental-feature SendableProhibitsMainActorInference
8+
9+
10+
@attached(extension, conformances: Sendable)
11+
macro AddSendable() = #externalMacro(module: "MacroDefinition", type: "SendableMacro")
12+
13+
@AddSendable
14+
final class SendableClass {
15+
var property: Int { 0 }
16+
17+
func f() { }
18+
}
19+
20+
nonisolated func acceptSendable<T: Sendable>(_: T) { }
21+
22+
@concurrent func test(sc: SendableClass) async {
23+
acceptSendable(sc) // SendableClass is Sendable
24+
acceptSendable(\SendableClass.property) // so is its property
25+
sc.f() // not on the main actor, so this is okay
26+
}

0 commit comments

Comments
 (0)