Skip to content

Commit 95eb6f2

Browse files
authored
Merge pull request #37776 from slavapestov/fix-future-request-cycles
Fix a couple of future request cycles
2 parents 25f2277 + d4c7164 commit 95eb6f2

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2684,7 +2684,18 @@ ConformanceChecker::getReferencedAssociatedTypes(ValueDecl *req) {
26842684
};
26852685

26862686
Walker walker(Proto, assocTypes);
2687-
req->getInterfaceType()->getCanonicalType().walk(walker);
2687+
2688+
// This dance below is to avoid calling getCanonicalType() on a
2689+
// GenericFunctionType, which creates a GenericSignatureBuilder, which
2690+
// can in turn trigger associated type inference and cause a cycle.
2691+
auto reqTy = req->getInterfaceType();
2692+
if (auto *funcTy = reqTy->getAs<GenericFunctionType>()) {
2693+
for (auto param : funcTy->getParams())
2694+
param.getPlainType()->getCanonicalType().walk(walker);
2695+
funcTy->getResult()->getCanonicalType().walk(walker);
2696+
} else {
2697+
reqTy->getCanonicalType().walk(walker);
2698+
}
26882699

26892700
return assocTypes;
26902701
}

lib/Sema/TypeCheckType.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,18 +1261,17 @@ static Type diagnoseUnknownType(TypeResolution resolution,
12611261
comp->getNameRef(), moduleType->getModule()->getName());
12621262
} else {
12631263
LookupResult memberLookup;
1264-
// Let's try to lookup given identifier as a member of the parent type,
1265-
// this allows for more precise diagnostic, which distinguishes between
1266-
// identifier not found as a member type vs. not found at all.
1267-
NameLookupOptions memberLookupOptions = lookupOptions;
1268-
memberLookupOptions |= NameLookupFlags::IgnoreAccessControl;
1269-
memberLookup = TypeChecker::lookupMember(dc, parentType,
1270-
comp->getNameRef(),
1271-
memberLookupOptions);
1264+
// Let's try to look any member of the parent type with the given name,
1265+
// even if it is not a type, allowing for a more precise diagnostic.
1266+
NLOptions memberLookupOptions = (NL_QualifiedDefault |
1267+
NL_IgnoreAccessControl);
1268+
SmallVector<ValueDecl *, 2> results;
1269+
dc->lookupQualified(parentType, comp->getNameRef(), memberLookupOptions,
1270+
results);
12721271

12731272
// Looks like this is not a member type, but simply a member of parent type.
1274-
if (!memberLookup.empty()) {
1275-
auto member = memberLookup[0].getValueDecl();
1273+
if (!results.empty()) {
1274+
auto member = results[0];
12761275
diags.diagnose(comp->getNameLoc(), diag::invalid_member_reference,
12771276
member->getDescriptiveKind(), member->getName(),
12781277
parentType)

0 commit comments

Comments
 (0)