Skip to content

Commit dd252c1

Browse files
committed
AST: Fix request cycle from ParameterizedProtocolType::getRequirements()
This fixes a regression from #76585. Fixes rdar://problem/139232031.
1 parent 8f66bf1 commit dd252c1

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
@@ -3754,10 +3754,18 @@ void ParameterizedProtocolType::getRequirements(
37543754
for (unsigned i : indices(argTypes)) {
37553755
auto argType = argTypes[i];
37563756
auto *assocType = assocTypes[i];
3757-
// Do a general type substitution here because the associated type might be
3758-
// from an inherited protocol, in which case we will evaluate a non-trivial
3759-
// conformance path.
3760-
auto subjectType = assocType->getDeclaredInterfaceType().subst(subMap);
3757+
3758+
Type subjectType;
3759+
if (baseType->isTypeParameter()) {
3760+
// Fast path.
3761+
subjectType = DependentMemberType::get(baseType, assocType);
3762+
} else {
3763+
// Do a general type substitution here because the associated type might be
3764+
// from an inherited protocol, in which case we will evaluate a non-trivial
3765+
// conformance path.
3766+
subjectType = assocType->getDeclaredInterfaceType().subst(subMap);
3767+
}
3768+
37613769
reqs.emplace_back(RequirementKind::SameType, subjectType, argType);
37623770
}
37633771
}

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)