Skip to content

Commit 6166b22

Browse files
committed
Fix compiler crasher on typealias with a cycle in the constraints
rdar://problem/52463696 SR-11052
1 parent da39eec commit 6166b22

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -928,19 +928,18 @@ static void maybeDiagnoseBadConformanceRef(DeclContext *dc,
928928
SourceLoc loc,
929929
TypeDecl *typeDecl) {
930930
auto protocol = dyn_cast<ProtocolDecl>(typeDecl->getDeclContext());
931-
if (!protocol)
932-
return;
933931

934932
// If we weren't given a conformance, go look it up.
935933
ProtocolConformance *conformance = nullptr;
936-
if (auto conformanceRef = TypeChecker::conformsToProtocol(
937-
parentTy, protocol, dc,
938-
(ConformanceCheckFlags::InExpression |
939-
ConformanceCheckFlags::SuppressDependencyTracking |
940-
ConformanceCheckFlags::SkipConditionalRequirements))) {
941-
if (conformanceRef->isConcrete())
942-
conformance = conformanceRef->getConcrete();
943-
}
934+
if (protocol)
935+
if (auto conformanceRef = TypeChecker::conformsToProtocol(
936+
parentTy, protocol, dc,
937+
(ConformanceCheckFlags::InExpression |
938+
ConformanceCheckFlags::SuppressDependencyTracking |
939+
ConformanceCheckFlags::SkipConditionalRequirements))) {
940+
if (conformanceRef->isConcrete())
941+
conformance = conformanceRef->getConcrete();
942+
}
944943

945944
// If any errors have occurred, don't bother diagnosing this cross-file
946945
// issue.
@@ -949,7 +948,7 @@ static void maybeDiagnoseBadConformanceRef(DeclContext *dc,
949948
return;
950949

951950
auto diagCode =
952-
(conformance && !conformance->getConditionalRequirementsIfAvailable())
951+
(!protocol || (conformance && !conformance->getConditionalRequirementsIfAvailable()))
953952
? diag::unsupported_recursion_in_associated_type_reference
954953
: diag::broken_associated_type_witness;
955954

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
protocol ProtoA {
4+
associatedtype AType1
5+
}
6+
7+
protocol ProtoB {
8+
associatedtype AType2: ProtoA
9+
func protoFunc() -> AType2.AType1
10+
}
11+
12+
extension ProtoB {
13+
typealias Alias = AType2.AType1
14+
}
15+
16+
struct Concrete<AType2: ProtoA>: ProtoB {
17+
18+
func concreteFunc() -> Alias {
19+
fatalError()
20+
}
21+
22+
func protoFunc() -> Alias { // expected-error{{unsupported recursion for reference to type alias 'Alias' of type 'Concrete<AType2>'}}
23+
fatalError()
24+
}
25+
}

0 commit comments

Comments
 (0)