Open mattmassicotte opened 2 months ago
This doesn't crash with my fix from https://github.com/swiftlang/swift/pull/76076.
Now I get:
test.swift:22:15: error: returning 'self'-isolated 'self.context' as a 'sending' result risks causing data races
20 | public func withContext<T>(_ block: sending (Context) throws -> T) async throws -> sending T {
21 | let value: T = try Transaction.with { txn in
22 | return try block(context)
| |- error: returning 'self'-isolated 'self.context' as a 'sending' result risks causing data races
| `- note: returning 'self'-isolated 'self.context' risks causing data races since the caller assumes that 'self.context' can be safely sent to other isolation domains
23 | }
24 |
There is something funky going on here. I am going out of town, I'll look further when I get back.
I do think that there does need to be an error here, just the error is messed up in some way.
.with expects its closure parameter to have a sending result... so the closure has a sending result... but block does not have a sending result. So you are returning a non-sending thing into a sending thing. Since context is actor isolated and the result of body is not sending, I would expect its result to be actor isolated as well... and one cannot return an actor isolated value as a sending result.
Yes, I agree with your analysis here. I think (hope) that had I not run into other issues, I would have figured that out myself. I'll be satisified with the crash resolved, but if you want to use this issue to look more closely at the error I'm all for it.
Yes. While I am here, I want to fix this.
Description
I think this has something to do with the
inout
+sending
combination in thewith
function. Removing either allows the code to be processed succesfully.Reproduction
Stack dump
Expected behavior
I think it's still a little unclear if this code should actually compile cleanly or produce an error due to:
https://github.com/swiftlang/swift/issues/75473
Environment
Apple Swift version 6.0-dev (LLVM 311c8b35213308e, Swift 488a207cc9d2994) Target: arm64-apple-macosx14.0
Additional information
No response