Avatar
Avatar
omochimetaru
@swift-6.2.3 -swift-version 6 class C { var x = 0 } func useC(_ c: C) {} actor A { init() {} var c: C? func setC(_ c: C) { self.c = c } } func main() async { let a = A() let c = C() await a.setC(c) useC(c) }
exit status 1 with stderr:<stdin>:20:13: error: sending 'c' risks causing data races [#SendingRisksDataRace] 18 | let a = A() 19 | let c = C() 20 | await a.setC(c) | |- error: sending 'c' risks causing data races [#SendingRisksDataRace] | `- note: sending 'c' to actor-isolated instance method 'setC' risks causing data races between actor-isolated and local nonisolated uses 21 | useC(c) | `- note: access can happen concurrently 22 | } 23 | [#SendingRisksDataRace]: <https://docs.swift.org/compiler/documentation/diagnostics/sending-risks-data-race>