Avatar
Avatar
omochimetaru
@swift-6.2.3 @swift-6.1.3 @swift-6.0.3 -swift-version 6 import Synchronization final class Foo { var value = 0 } func main() { let mutex = Mutex(Foo()) let foo = mutex.withLock { $0 } Task.detached { let foo = mutex.withLock { $0 } foo.value += 1 } foo.value += 1 }
exit status 1 with stderr:<stdin>:10:35: error: 'inout sending' parameter '$0' cannot be task-isolated at end of function 8 | let mutex = Mutex(Foo()) 9 | 10 | let foo = mutex.withLock { $0 } | |- error: 'inout sending' parameter '$0' cannot be task-isolated at end of function | `- note: task-isolated '$0' risks causing races in between task-isolated uses and caller uses since caller assumes value is not actor isolated 11 | 12 | Task.detached { <stdin>:13:39: error: 'inout sending' parameter '$0' cannot be task-isolated at end of function 11 | 12 | Task.detached { 13 | let foo = mutex.withLock { $0 } | |- error: 'inout sending' parameter '$0' cannot be task-isolated at end of function | `- note: task-isolated '$0' risks causing races in between task-isolated uses and caller uses since caller assumes value is not actor isolated 14 | foo.value += 1 15 | }