Skip to content

Commit 5a6d928

Browse files
committed
[Sema]Skip Sendable conformance check when are added to parameters or return types of an actor-isolated function
1 parent 55189ba commit 5a6d928

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,9 @@ bool swift::diagnoseNonSendableTypesInReference(
11661166
if (funcCheckOptions.contains(FunctionCheckKind::Params)) {
11671167
// only check params if funcCheckKind specifies so
11681168
for (auto param : *function->getParameters()) {
1169+
if (param->isSending())
1170+
return true;
1171+
11691172
Type paramType = param->getInterfaceType().subst(subs);
11701173
if (diagnoseNonSendableTypes(
11711174
paramType, fromDC, derivedConformanceType,
@@ -1179,6 +1182,9 @@ bool swift::diagnoseNonSendableTypesInReference(
11791182
// Check the result type of a function.
11801183
if (auto func = dyn_cast<FuncDecl>(function)) {
11811184
if (funcCheckOptions.contains(FunctionCheckKind::Results)) {
1185+
if (func->hasSendingResult())
1186+
return true;
1187+
11821188
// only check results if funcCheckKind specifies so
11831189
Type resultType = func->getResultInterfaceType().subst(subs);
11841190
if (diagnoseNonSendableTypes(

test/Sema/issue-76710.swift

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 6
2+
3+
// https://github.com/swiftlang/swift/issues/76710
4+
5+
class NonSendableKlass1 {}
6+
7+
protocol P1 {
8+
func bar(_ a: sending NonSendableKlass1) async -> sending NonSendableKlass1
9+
}
10+
11+
@MainActor
12+
class P1Class: P1 {
13+
func bar(_ a: sending NonSendableKlass1) async -> sending NonSendableKlass1 { a }
14+
}
15+
16+
class NonSendableKlass2 {}
17+
// expected-note@-1 2{{class 'NonSendableKlass2' does not conform to the 'Sendable' protocol}}
18+
19+
protocol P2 {
20+
func bar(_ a: NonSendableKlass2) async -> NonSendableKlass2
21+
}
22+
23+
@MainActor
24+
class P2Class: P2 {
25+
func bar(_ a: NonSendableKlass2) async -> NonSendableKlass2 { a }
26+
// expected-error@-1 {{non-sendable type 'NonSendableKlass2' cannot be returned from main actor-isolated implementation to caller of protocol requirement 'bar'}}
27+
// expected-error@-2 {{non-sendable parameter type 'NonSendableKlass2' cannot be sent from caller of protocol requirement 'bar' into main actor-isolated implementation}}
28+
}
29+
30+
class NonSendableKlass3 {}
31+
32+
protocol P3 {
33+
func bar(_ a: sending NonSendableKlass3) async -> sending NonSendableKlass3
34+
}
35+
36+
actor P3Actor: P3 {
37+
func bar(_ a: sending NonSendableKlass3) async -> sending NonSendableKlass3 { NonSendableKlass3() }
38+
}
39+
40+
class NonSendableKlass4 {}
41+
// expected-note@-1 2{{class 'NonSendableKlass4' does not conform to the 'Sendable' protocol}}
42+
43+
protocol P4 {
44+
func bar(_ a: NonSendableKlass4) async -> NonSendableKlass4
45+
}
46+
47+
actor P4Actor: P4 {
48+
func bar(_ a: NonSendableKlass4) async -> NonSendableKlass4 { NonSendableKlass4() }
49+
// expected-error@-1 {{non-sendable type 'NonSendableKlass4' cannot be returned from actor-isolated implementation to caller of protocol requirement 'bar'}}
50+
// expected-error@-2 {{non-sendable parameter type 'NonSendableKlass4' cannot be sent from caller of protocol requirement 'bar' into actor-isolated implementation}}
51+
}
52+

0 commit comments

Comments
 (0)