mroi
(Michael Roitzsch)
August 6, 2022, 11:16am
1
I am getting this warning with Xcode14 beta 4 (14A5284g) as well as the 5.7 snapshot from August 2nd:
actor Test {
@TaskLocal static var local: Int?
func run() async {
await Self.$local.withValue(42) { ⚠️
await work()
}
}
func work() async {
print("Hello \(Self.local ?? 0)")
}
}
await Test().run()
non-sendable type '() async throws -> ()' exiting actor-isolated context in call to non-isolated instance method 'withValue(_:operation:file:line:)' cannot cross actor boundary
I am not sure how to deal with this. Is this legal code and the diagnostic is wrong or am I mis-using task local values?
1 Like
Did you find a solution? I still have this warning with Xcode 14.1.
mroi
(Michael Roitzsch)
November 22, 2022, 8:34am
3
Same for me. I keep testing, but I also still get the warning. Have not found a good way around it.
ktoso
(Konrad 'ktoso' Malawski 🐟🏴☠️)
November 22, 2022, 9:25am
4
Please file a bug on GitHub - apple/swift: The Swift Programming Language - I’ll give it a look though this was too easy to miss on the forums. Perhaps we need to annotate the closure with some more hints here, but on phone now so hard to verify.
To clarify: This is legal code and should not produce warnings.
mroi
(Michael Roitzsch)
November 22, 2022, 12:41pm
5
Thanks for the clarification that this should be legal. I was not really sure since I just started using Swift concurrency. Issue #62220 on GitHub opened.
1 Like
ktoso
(Konrad 'ktoso' Malawski 🐟🏴☠️)
November 22, 2022, 1:23pm
6
Thank you! I’ll have a look at it.
1 Like
ktoso
(Konrad 'ktoso' Malawski 🐟🏴☠️)
November 24, 2022, 5:11am
7
Thanks again, to close the loop here: it's a missing Sendable annotation, will be fixed in here: Actor boundary warning for @TaskLocal values · Issue #62220 · apple/swift · GitHub
2 Likes
mroi
(Michael Roitzsch)
December 16, 2022, 10:31am
8
Can confirm that Swift nightly no longer emits the warning. Thanks @ktoso for looking into this!
1 Like
ktoso
(Konrad 'ktoso' Malawski 🐟🏴☠️)
December 16, 2022, 10:31am
9
Sweet, thanks for confirming