Skip to content

Commit 94e9263

Browse files
committed
Sema: Fix crash on circular reference in checkContextualRequirements()
The call to getGenericSignature() might return nullptr if we encounter a circular reference. Fixes <rdar://problem/64992293>.
1 parent ec5da74 commit 94e9263

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
@@ -619,6 +619,8 @@ static Type checkContextualRequirements(Type type,
619619
return type;
620620
}
621621

622+
auto &ctx = dc->getASTContext();
623+
622624
SourceLoc noteLoc;
623625
{
624626
// We are interested in either a contextual where clause or
@@ -637,6 +639,13 @@ static Type checkContextualRequirements(Type type,
637639

638640
const auto subMap = parentTy->getContextSubstitutions(decl->getDeclContext());
639641
const auto genericSig = decl->getGenericSignature();
642+
if (!genericSig) {
643+
ctx.Diags.diagnose(loc, diag::recursive_decl_reference,
644+
decl->getDescriptiveKind(), decl->getName());
645+
decl->diagnose(diag::kind_declared_here, DescriptiveDeclKind::Type);
646+
return ErrorType::get(ctx);
647+
}
648+
640649
const auto result =
641650
TypeChecker::checkGenericArguments(
642651
dc, loc, noteLoc, type,
@@ -647,7 +656,7 @@ static Type checkContextualRequirements(Type type,
647656
switch (result) {
648657
case RequirementCheckResult::Failure:
649658
case RequirementCheckResult::SubstitutionFailure:
650-
return ErrorType::get(dc->getASTContext());
659+
return ErrorType::get(ctx);
651660
case RequirementCheckResult::Success:
652661
return type;
653662
}
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)