mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user