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-11896] Key path obtained through dynamic member lookup is incorrectly writable #54313

Closed
hamishknight opened this issue Dec 4, 2019 · 1 comment
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself key paths Feature: key paths (both native and Objective-C) type checker Area → compiler: Semantic analysis

Comments

@hamishknight
Copy link
Collaborator

Previous ID SR-11896
Radar None
Original Reporter @hamishknight
Type Bug
Status Closed
Resolution Done
Environment

Swift version 5.1.2-dev (Swift b7537cf)
Target: x86_64-apple-darwin18.5.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, KeyPaths, TypeChecker
Assignee @hamishknight
Priority Medium

md5: a26a851e8f52793c8b691e34ce2913af

Issue Description:

We incorrectly allow the following code to compile:

struct S {
  var i: Int
}

@dynamicMemberLookup
struct R {
  subscript(dynamicMember kp: KeyPath<S, Int>) -> Int { 5 }
}

let kp = \R.i
var r = R()
r[keyPath: kp] = 5

The key path \R.i is incorrectly inferred to be a WritableKeyPath, it should instead have been inferred as a KeyPath due to the fact that it's transformed into \R.[dynamicMember: \S.i], and the dynamicMember: subscript is not settable.

@hamishknight
Copy link
Collaborator Author

Fixed by #28569

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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 key paths Feature: key paths (both native and Objective-C) type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

1 participant