Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler loses ability to infer Root of KeyPath when it is Optional and Sendable #76716

Open
iwt-dahlborn opened this issue Sep 26, 2024 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@iwt-dahlborn
Copy link

iwt-dahlborn commented Sep 26, 2024

Description

When you require a keypath to be Sendable using & Sendable and then make that Optional the compiler loses the ability to infer the root and the KeyPath always needs to be fully qualified to compile.

Reproduction

import Foundation

struct SendableTest: Sendable {
    var text: String = "Hello, World!"
}

struct Storage {
    let keyPath: KeyPath<SendableTest, String> & Sendable
    let optionalKeyPath: (KeyPath<SendableTest, String> & Sendable)?
    let nonSendableKeyPath: KeyPath<SendableTest, String>
    let nonSendableOptionalKeyPath: KeyPath<SendableTest, String>?
}

let storage = Storage(
    keyPath: \.text,
    // Cannot convert value of type 'KeyPath<_, String>'
    // to expected argument type 'KeyPath<SendableTest, String>'
    optionalKeyPath: \.text,
    nonSendableKeyPath: \.text,
    nonSendableOptionalKeyPath: \.text
)

Expected behavior

The Root should be inferable even if the sendable keypath is optional.

Environment

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

Additional information

No response

@iwt-dahlborn iwt-dahlborn added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Sep 26, 2024
@stephencelis
Copy link
Contributor

@xedin I believe you were aware of a similar issue with appending sendable key paths, so I wonder if this should be grouped in the same issue bucket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

2 participants