Skip to content

Commit ef5b9dc

Browse files
authored
Merge pull request #77385 from slavapestov/fix-rdar139232031
AST: Fix request cycle from ParameterizedProtocolType::getRequirements()
2 parents 2503384 + dd252c1 commit ef5b9dc

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/AST/Type.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3735,10 +3735,18 @@ void ParameterizedProtocolType::getRequirements(
37353735
for (unsigned i : indices(argTypes)) {
37363736
auto argType = argTypes[i];
37373737
auto *assocType = assocTypes[i];
3738-
// Do a general type substitution here because the associated type might be
3739-
// from an inherited protocol, in which case we will evaluate a non-trivial
3740-
// conformance path.
3741-
auto subjectType = assocType->getDeclaredInterfaceType().subst(subMap);
3738+
3739+
Type subjectType;
3740+
if (baseType->isTypeParameter()) {
3741+
// Fast path.
3742+
subjectType = DependentMemberType::get(baseType, assocType);
3743+
} else {
3744+
// Do a general type substitution here because the associated type might be
3745+
// from an inherited protocol, in which case we will evaluate a non-trivial
3746+
// conformance path.
3747+
subjectType = assocType->getDeclaredInterfaceType().subst(subMap);
3748+
}
3749+
37423750
reqs.emplace_back(RequirementKind::SameType, subjectType, argType);
37433751
}
37443752
}

test/Generics/rdar139232031.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
protocol P1 {
4+
associatedtype A
5+
associatedtype B
6+
}
7+
8+
protocol P2<A>: P1 where B: P2<A> {}

0 commit comments

Comments
 (0)