Skip to content

Commit a405da4

Browse files
authored
Merge pull request #32776 from slavapestov/fix-circularity-crash
Sema: Fix crash on circular reference in checkContextualRequirements()
2 parents 6061fe6 + 1f5433f commit a405da4

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

lib/Sema/TypeCheckType.cpp

+10-1
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
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-frontend -emit-ir %s
2+
3+
public class Clazz {}
4+
5+
public protocol SelectableFieldValueProtocol {}
6+
7+
public protocol FieldProtocol {
8+
associatedtype SelectableValue : SelectableFieldValueProtocol
9+
}
10+
11+
public protocol SelectFieldValueCoordinatorDelegate {
12+
associatedtype Field : Clazz, FieldProtocol
13+
}
14+
15+
public class SelectFieldValueCoordinator<Field, Delegate : SelectFieldValueCoordinatorDelegate> where Field == Delegate.Field {}
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)