@@ -5821,6 +5821,15 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
5821
5821
}
5822
5822
}
5823
5823
5824
+ // Exclude some of the dynamic member choices from results
5825
+ // because using such choices would result in a self-recursive reference.
5826
+ //
5827
+ // This is required because if there are no viable/unviable choices
5828
+ // `performMemberLookup` is going to attempt to lookup inaccessible
5829
+ // members and results would include dynamic member subscripts which
5830
+ // have already been excluded.
5831
+ llvm::SmallPtrSet<ValueDecl *, 2 > excludedDynamicMembers;
5832
+
5824
5833
// Local function that adds the given declaration if it is a
5825
5834
// reasonable choice.
5826
5835
auto addChoice = [&](OverloadChoice candidate) {
@@ -5997,8 +6006,10 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
5997
6006
if (auto kpElt = memberLocator->getLastElementAs <KPDynamicMemberElt>()) {
5998
6007
auto *keyPath = kpElt->getKeyPathDecl ();
5999
6008
if (isSelfRecursiveKeyPathDynamicMemberLookup (*this , baseTy,
6000
- memberLocator))
6009
+ memberLocator)) {
6010
+ excludedDynamicMembers.insert (candidate.getDecl ());
6001
6011
return ;
6012
+ }
6002
6013
6003
6014
if (auto *storage = dyn_cast<AbstractStorageDecl>(decl)) {
6004
6015
// If this is an attempt to access read-only member via
@@ -6234,6 +6245,9 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
6234
6245
return result;
6235
6246
}
6236
6247
6248
+ if (excludedDynamicMembers.count (cand))
6249
+ continue ;
6250
+
6237
6251
result.addUnviable (getOverloadChoice (cand, /* isBridged=*/ false ,
6238
6252
/* isUnwrappedOptional=*/ false ),
6239
6253
MemberLookupResult::UR_Inaccessible);
0 commit comments