Skip to content

Commit 156a43d

Browse files
committed
[Concurrency] Make sure that conversion that switches from one actor to another is not accepted
1 parent 23739ef commit 156a43d

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

lib/Sema/TypeCheckConcurrency.cpp

+3-9
Original file line numberDiff line numberDiff line change
@@ -2795,15 +2795,6 @@ namespace {
27952795
toFnType, /*downgradeToWarning=*/true);
27962796
break;
27972797

2798-
case FunctionTypeIsolation::Kind::GlobalActor:
2799-
// Actor isolation change.
2800-
if (fromIsolation.getGlobalActorType()->isEqual(
2801-
toIsolation.getGlobalActorType())) {
2802-
diagnoseNonSendableParametersAndResult(
2803-
toFnType, /*downgradeToWarning=*/true);
2804-
}
2805-
break;
2806-
28072798
case FunctionTypeIsolation::Kind::NonIsolated: {
28082799
// Since @execution(concurrent) as an asynchronous
28092800
// function it would mean that without Sendable
@@ -2821,6 +2812,9 @@ namespace {
28212812
// Runs on the actor.
28222813
case FunctionTypeIsolation::Kind::NonIsolatedCaller:
28232814
break;
2815+
2816+
case FunctionTypeIsolation::Kind::GlobalActor:
2817+
llvm_unreachable("invalid conversion");
28242818
}
28252819
break;
28262820
}

test/Concurrency/attr_execution_conversions.swift

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
// REQUIRES: concurrency
55
// REQUIRES: swift_feature_ExecutionAttribute
66

7+
@globalActor
8+
actor MyActor {
9+
static let shared = MyActor()
10+
}
11+
712
@execution(concurrent)
813
func concurrentTest() async {
914
}
@@ -132,4 +137,9 @@ func testNonSendableDiagnostics(
132137

133138
let _: @MainActor (NonSendable) async -> Void = caller1 // Ok
134139
let _: @MainActor () async -> NonSendable = caller2 // Ok
140+
141+
let _: @MyActor (NonSendable) async -> Void = globalActor1
142+
// expected-error@-1 {{cannot convert value actor-isolated to 'MainActor' to specified type actor-isolated to 'MyActor'}}
143+
let _: @MyActor () async -> NonSendable = globalActor2
144+
// expected-error@-1 {{cannot convert value actor-isolated to 'MainActor' to specified type actor-isolated to 'MyActor'}}
135145
}

0 commit comments

Comments
 (0)