Closed
Description
Description
Attached examples demonstrates a valid code which produces unexpected compilation error
Reproduction
struct WritableActorKeyPath<Root: Actor, Value>: Sendable {
var getter: @Sendable (isolated Root) -> Value
var setter: @Sendable (isolated Root, Value) -> Void
subscript(_ root: isolated Root) -> Value {
get { getter(root) } // error: call to actor-isolated function in a synchronous actor-isolated context
nonmutating set { setter(root, newValue) } // error: call to actor-isolated function in a synchronous actor-isolated context
}
}
Expected behavior
Example should compile without errors
Environment
$ xcrun swiftc -version
swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: arm64-apple-macosx15.0
Additional information
Note that issue does not reproduce for plain functions, only for subscripts:
func testGet<Root: Actor, Value>(_ root: isolated Root, getter: (isolated Root) -> Value) -> Value {
return getter(root) // ok
}
func testSet<Root: Actor, Value>(_ root: isolated Root, setter: (isolated Root, Value) -> Void, newValue: Value) {
setter(root, newValue) // ok
}
No response