[6.0][region-isolation] Improve the error we emit for closure literals captured as a sending parameter. #75887
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation: [6.0][region-isolation] Improve the error we emit for closure literals captured as a sending parameter.
Before region isolation and sending closures, Task.init took an
@Sendable
closure. If non-Sendable state was captured in the closure, we emitted a specific error on the captured value. This provided a discoverable bread crumb that the user could use to trace back what the exact problem was (noting that takeSendableClosure is where Task.init) would be:When we introduced region isolation and changed Task.init to take a sending closure, we regressed this behavior unintentionally. With region isolation and a sending closure the above error is emitted instead:
this doesn't provide a breadcrumb for the user to work back from anymore. With this change, we ameliorate this situation by introducing a special diagnostic that ensures that the user always has a breadcrumb. With this change, we now get the following error message:
Radars:
Original PRs:
Risk: Low. This does not impact where we emit errors... it just changes the actual error that we are emitting. Also, I pattern matched specifically against closure literals passed as a sending parameter, so if I did introduce a problem, it will occur narrowly just in this case (a case that we were already going to reject anyways). So the potential fallout is not large. Also this only applies to swift 6 and swift 5 + strict-concurrency.