Open dfed opened 1 month ago
of possible relevance for triage & investigation: if you make function
in the above example async
, the error appears to go away
Solid insight @jamieQ!
Riffing on that, making the functionReference
itself async
gets things compiling. The following code compiles:
@MainActor
final class MainActorTest {
func function() {}
func referenceFunction() {
let functionReference: (MainActorTest) -> @MainActor () async -> () = MainActorTest.function
_ = functionReference(self)
}
}
Worth noting that the workaround above only works if the function reference is assigned locally. If the function reference is a parameter to a method this workaround does not work.
Description
With the Swift 6 compiler mode turned on, it is not possible to reference a
@MainActor
-bound instance method's function reference. Doing so results in aCall to main actor-isolated instance method '<functionName>' in a synchronous nonisolated context.
error, even when the reference is made in a@MainActor
-bound method.Reproduction
Note that the line:
can also read as:
And result in the same error.
Expected behavior
The above code compiles without issue.
Environment
swift-driver version: 1.110 Apple Swift version 6.0 (swiftlang-6.0.0.4.52 clang-1600.0.21.1.3) Target: arm64-apple-macosx14.0
Additional information
No response