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

[SR-14272] Writing to WritableKeyPath of a constant of a class doesn't compile if the keypath is a variable #56632

Open
Cyberbeni opened this issue Feb 25, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@Cyberbeni
Copy link

Previous ID SR-14272
Radar rdar://problem/74747101
Original Reporter @Cyberbeni
Type Bug
Environment

Xcode 12.4

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 109ad3aa3be28c66d6315bd2a6d417ea

Issue Description:

class A {
    var a = false
}


class B {
    let a = A()
}


let b: B = B()
let keyPath: WritableKeyPath<A, Bool> = \.a
b.a[keyPath: \.a] = true // This compiles and works as expected
b.a[keyPath: keyPath] = true // Compilation error: Cannot assign through subscript: 'a' is a 'let' constant
var a = b.a
a[keyPath: keyPath] = true // Workaround

I would expect the last line to work just as the line before it.

@typesanitizer
Copy link

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants