Skip to content

False positive in isolation checking subscript isolated to an argument #80992

Closed
@nickolas-pohilets

Description

@nickolas-pohilets

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.concurrencyFeature: umbrella label for concurrency language features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions