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-9452] KeyPaths allow mutating a "let" constant #51915

Closed
swift-ci opened this issue Dec 9, 2018 · 0 comments
Closed

[SR-9452] KeyPaths allow mutating a "let" constant #51915

swift-ci opened this issue Dec 9, 2018 · 0 comments
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)

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Dec 9, 2018

Previous ID SR-9452
Radar None
Original Reporter dkyowell (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 10.1, Swift 4.2, MacOS 10.14.1

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

md5: 3dabe52f392fc0f7c5177c869bf8a8c7

duplicates:

  • SR-6502 WritableKeyPath allows writing to immutable properties

Issue Description:

Force casting a KeyPath to a ReferenceWritableKeyPath allows "let" constant values to be mutated.

import Foundation

class Sample {
    let value: Int = 99
}

let sample = Sample()
let keyPath = \Sample.value
sample[keyPath: keyPath as! ReferenceWritableKeyPath<Sample, Int>] = 100
print(sample.value)
// prints 100
@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)
Projects
None yet
Development

No branches or pull requests

1 participant