Skip to content

Commit 3c30bb1

Browse files
committed
[transferring] Transferring results shouldn't have the following error emitted: "non-sendable type 'NonSendableKlass' returned by implicitly asynchronous call to main actor-isolated function cannot cross actor boundary"
Transferring makes this safe. rdar://123712033
1 parent 3b9d452 commit 3c30bb1

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3508,8 +3508,11 @@ namespace {
35083508
diagnoseApplyArgSendability(apply, getDeclContext());
35093509
}
35103510

3511-
// Check for sendability of the result type.
3512-
if (diagnoseNonSendableTypes(
3511+
// Check for sendability of the result type if we do not have a
3512+
// transferring result.
3513+
if ((!ctx.LangOpts.hasFeature(Feature::TransferringArgsAndResults) ||
3514+
!fnType->hasTransferringResult()) &&
3515+
diagnoseNonSendableTypes(
35133516
fnType->getResult(), getDeclContext(),
35143517
/*inDerivedConformance*/Type(),
35153518
apply->getLoc(),

test/Concurrency/transfernonsendable_strong_transferring_results.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ func transferAsyncResultWithTransferringArg(_ x: transferring NonSendableKlass)
4949
func transferAsyncResultWithTransferringArg2(_ x: transferring NonSendableKlass, _ y: NonSendableKlass) async -> transferring NonSendableKlass { NonSendableKlass() }
5050
func transferAsyncResultWithTransferringArg2Throwing(_ x: transferring NonSendableKlass, _ y: NonSendableKlass) async throws -> transferring NonSendableKlass { NonSendableKlass() }
5151

52+
@MainActor func transferAsyncResultMainActor() async -> transferring NonSendableKlass { NonSendableKlass() }
53+
5254
@MainActor var globalNonSendableKlass = NonSendableKlass()
5355

5456
/////////////////
@@ -106,3 +108,11 @@ func transferReturnArg(_ x: NonSendableKlass) -> transferring NonSendableKlass {
106108
func transferReturnArgTuple(_ x: transferring NonSendableKlass) -> transferring (NonSendableKlass, NonSendableKlass) {
107109
return (x, x)
108110
}
111+
112+
func useTransferredResultMainActor() async {
113+
let _ = await transferAsyncResultMainActor()
114+
}
115+
116+
func useTransferredResult() async {
117+
let _ = await transferAsyncResult()
118+
}

0 commit comments

Comments
 (0)