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:
Mark Lacey
2018-05-08 12:35:41 -07:00
parent efa36efcd0
commit 83ebd71644
5 changed files with 46 additions and 4 deletions

View File

@@ -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;