swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.65k stars 10.38k forks source link

[Concurrency] ReferenceWritableKeyPath of main-actor bound property cannot be created inside a non-isolated context #77774

Open xavierjurado opened 4 days ago

xavierjurado commented 4 days ago

Description

While using a ReferenceWritableKeyPath should be limited to the actor where the property it's referencing is bound, creating such key path should be allowed on any context.

Reproduction

  nonisolated func testKeyPath() {
    let keyPath: ReferenceWritableKeyPath<UIView, _> = \.backgroundColor // Error: Cannot form key path to main actor-isolated property 'backgroundColor'
  }

Expected behavior

ReferenceWritableKeyPath can be created from any context, but the compiler prevents applying such keypath outside of the context where the property is bound (ie: outside of @MainActor in the example above).

Environment

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)

Additional information

cc @hborla