Skip to content

Commit c698f7c

Browse files
committed
[region-isolation] Use the user facing type rather than the SIL type when emitting a function argument captured by actor isolated closure error.
1 parent 37bae7a commit c698f7c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,8 +1038,8 @@ class TransferNonTransferrableDiagnosticInferrer {
10381038
}
10391039

10401040
static UseDiagnosticInfo
1041-
forFunctionArgumentClosure(ApplyIsolationCrossing isolation) {
1042-
return {UseDiagnosticInfoKind::FunctionArgumentClosure, isolation};
1041+
forFunctionArgumentClosure(ApplyIsolationCrossing isolation, Type inferredType) {
1042+
return {UseDiagnosticInfoKind::FunctionArgumentClosure, isolation, inferredType};
10431043
}
10441044

10451045
static UseDiagnosticInfo forFunctionArgumentApplyStronglyTransferred(Type inferredType) {
@@ -1107,8 +1107,9 @@ bool TransferNonTransferrableDiagnosticInferrer::initForIsolatedPartialApply(
11071107
for (auto &p : foundCapturedIsolationCrossing) {
11081108
if (std::get<1>(p) == opIndex) {
11091109
loc = std::get<0>(p).getLoc();
1110+
Type type = std::get<0>(p).getDecl()->getInterfaceType();
11101111
diagnosticInfo =
1111-
UseDiagnosticInfo::forFunctionArgumentClosure(std::get<2>(p));
1112+
UseDiagnosticInfo::forFunctionArgumentClosure(std::get<2>(p), type);
11121113
return true;
11131114
}
11141115
}
@@ -1269,7 +1270,7 @@ void TransferNonSendableImpl::emitTransferredNonTransferrableDiagnostics() {
12691270
}
12701271
case UseDiagnosticInfoKind::FunctionArgumentClosure: {
12711272
diagnoseError(astContext, loc, diag::regionbasedisolation_arg_transferred,
1272-
op->get()->getType().getASTType(),
1273+
diagnosticInfo.getType(),
12731274
diagnosticInfo.getIsolationCrossing().getCalleeIsolation())
12741275
.highlight(op->getUser()->getLoc().getSourceRange());
12751276
// Only emit the note if our value is different from the function

test/Concurrency/transfernonsendable.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,3 +1465,9 @@ final actor FinalActorWithSetter {
14651465
// expected-tns-warning @-1 {{task isolated value of type 'NonSendableKlass' transferred to main actor-isolated context}}
14661466
}
14671467
}
1468+
1469+
func functionArgumentIntoClosure(_ x: @escaping () -> ()) async {
1470+
let _ = { @MainActor in
1471+
let _ = x // expected-tns-warning {{task isolated value of type '() -> ()' transferred to main actor-isolated context}}
1472+
}
1473+
}

0 commit comments

Comments
 (0)