mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Allowing forming WritableKeyPath to read-only value in Swift 3/4.
We inadvertantly allowed this in the past, so continue to do so when compiling in Swift 3/4 mode to avoid suddenly breaking existing code. The diagnostic here is pretty bad, and I've opened issues for that as well as providing some kind of deprecation warning for this so that even under Swift 3/4 mode we alert users that this is unsupported. rdar://problem/39802797
This commit is contained in:
@@ -4036,8 +4036,19 @@ ConstraintSystem::simplifyKeyPathConstraint(Type keyPathTy,
|
||||
// get any special power from being formed in certain contexts, such
|
||||
// as the ability to assign to `let`s in initialization contexts, so
|
||||
// we pass null for the DC to `isSettable` here.)
|
||||
if (!storage->isSettable(nullptr)
|
||||
|| !storage->isSetterAccessibleFrom(DC)) {
|
||||
if (!getASTContext().isSwiftVersionAtLeast(5)) {
|
||||
// As a source-compatibility measure, continue to allow
|
||||
// WritableKeyPaths to be formed in the same conditions we did
|
||||
// in previous releases even if we should not be able to set
|
||||
// the value in this context.
|
||||
if (!storage->isSettable(DC)) {
|
||||
// A non-settable component makes the key path read-only, unless
|
||||
// a reference-writable component shows up later.
|
||||
capability = ReadOnly;
|
||||
continue;
|
||||
}
|
||||
} else if (!storage->isSettable(nullptr)
|
||||
|| !storage->isSetterAccessibleFrom(DC)) {
|
||||
// A non-settable component makes the key path read-only, unless
|
||||
// a reference-writable component shows up later.
|
||||
capability = ReadOnly;
|
||||
|
||||
Reference in New Issue
Block a user