Skip to content

Commit fc45397

Browse files
authored
Merge pull request #33350 from CodaFi/a-circle-most-vicious
[5.3] Fix crash on circular reference in checkContextualRequirements()
2 parents 8d99f24 + d5a7cc4 commit fc45397

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,8 @@ static Type checkContextualRequirements(Type type,
651651
return type;
652652
}
653653

654+
auto &ctx = dc->getASTContext();
655+
654656
SourceLoc noteLoc;
655657
{
656658
// We are interested in either a contextual where clause or
@@ -669,6 +671,13 @@ static Type checkContextualRequirements(Type type,
669671

670672
const auto subMap = parentTy->getContextSubstitutions(decl->getDeclContext());
671673
const auto genericSig = decl->getGenericSignature();
674+
if (!genericSig) {
675+
ctx.Diags.diagnose(loc, diag::recursive_decl_reference,
676+
decl->getDescriptiveKind(), decl->getName());
677+
decl->diagnose(diag::kind_declared_here, DescriptiveDeclKind::Type);
678+
return ErrorType::get(ctx);
679+
}
680+
672681
const auto result =
673682
TypeChecker::checkGenericArguments(
674683
dc, loc, noteLoc, type,
@@ -681,7 +690,7 @@ static Type checkContextualRequirements(Type type,
681690
switch (result) {
682691
case RequirementCheckResult::Failure:
683692
case RequirementCheckResult::SubstitutionFailure:
684-
return ErrorType::get(dc->getASTContext());
693+
return ErrorType::get(ctx);
685694
case RequirementCheckResult::Success:
686695
return type;
687696
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: not %target-swift-frontend -typecheck %s
2+
3+
public protocol SomeProtocol {}
4+
5+
public struct Impl<Param>: SomeProtocol where Param: SomeProtocol {}
6+
7+
public struct Wrapper<Content> where Content: SomeProtocol {}
8+
9+
public extension Wrapper where Content == Impl<WrapperParam> {
10+
typealias WrapperParam = SomeProtocol
11+
}
12+

0 commit comments

Comments
 (0)