@@ -4916,34 +4916,18 @@ ConstraintSystem::simplifyKeyPathConstraint(Type keyPathTy,
4916
4916
if (!storage) {
4917
4917
return SolutionKind::Error;
4918
4918
}
4919
-
4920
- // See whether key paths can store to this component. (Key paths don't
4921
- // get any special power from being formed in certain contexts, such
4922
- // as the ability to assign to `let`s in initialization contexts, so
4923
- // we pass null for the DC to `isSettable` here.)
4924
- if (!getASTContext ().isSwiftVersionAtLeast (5 )) {
4925
- // As a source-compatibility measure, continue to allow
4926
- // WritableKeyPaths to be formed in the same conditions we did
4927
- // in previous releases even if we should not be able to set
4928
- // the value in this context.
4929
- if (!storage->isSettable (DC)) {
4930
- // A non-settable component makes the key path read-only, unless
4931
- // a reference-writable component shows up later.
4932
- capability = ReadOnly;
4933
- continue ;
4934
- }
4935
- } else if (!storage->isSettable (nullptr )
4936
- || !storage->isSetterAccessibleFrom (DC)) {
4937
- // A non-settable component makes the key path read-only, unless
4938
- // a reference-writable component shows up later.
4919
+
4920
+ if (isReadOnlyKeyPathComponent (storage)) {
4939
4921
capability = ReadOnly;
4940
4922
continue ;
4941
4923
}
4924
+
4942
4925
// A nonmutating setter indicates a reference-writable base.
4943
4926
if (!storage->isSetterMutating ()) {
4944
4927
capability = ReferenceWritable;
4945
4928
continue ;
4946
4929
}
4930
+
4947
4931
// Otherwise, the key path maintains its current capability.
4948
4932
break ;
4949
4933
}
@@ -4991,8 +4975,9 @@ ConstraintSystem::simplifyKeyPathConstraint(Type keyPathTy,
4991
4975
if (keyPathBGT) {
4992
4976
if (keyPathBGT->getDecl () == getASTContext ().getKeyPathDecl ())
4993
4977
kpDecl = getASTContext ().getKeyPathDecl ();
4994
- else if (keyPathBGT->getDecl () == getASTContext ().getWritableKeyPathDecl ()
4995
- && capability >= Writable)
4978
+ else if (keyPathBGT->getDecl () ==
4979
+ getASTContext ().getWritableKeyPathDecl () &&
4980
+ capability >= Writable)
4996
4981
kpDecl = getASTContext ().getWritableKeyPathDecl ();
4997
4982
}
4998
4983
0 commit comments