Sema: Fix setter visibility computation when checking key path literals.

`AbstractStorageDecl::isSettable` by itself doesn't account for access control, so we need to check `isSetterAccessibleFrom` as well. Furthermore, key paths should not get the special context-sensitive privileges direct accesses do, such as initializers being able to assign into `let` properties. Fix the type checking logic here to only create a statically writable KeyPath value when the referenced declaration has a setter visible independent of current context. Fixes SR-6667 | rdar://problem/36257266.
This commit is contained in:
Joe Groff
2018-04-06 16:47:53 -07:00
parent 6df8732a02
commit 6d053f5a9c
2 changed files with 52 additions and 1 deletions

View File

@@ -4033,7 +4033,12 @@ ConstraintSystem::simplifyKeyPathConstraint(Type keyPathTy,
return SolutionKind::Error;
}
if (!storage->isSettable(DC)) {
// See whether key paths can store to this component. (Key paths don't
// 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)) {
// A non-settable component makes the key path read-only, unless
// a reference-writable component shows up later.
capability = ReadOnly;