Skip to content

Commit 5092d18

Browse files
authored
Merge pull request #26653 from xymus/fix-ta-to-ta
Fix compiler crasher on type alias with a cycle in the constraints
2 parents 937deb4 + 6166b22 commit 5092d18

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
@@ -937,19 +937,18 @@ static void maybeDiagnoseBadConformanceRef(DeclContext *dc,
937937
SourceLoc loc,
938938
TypeDecl *typeDecl) {
939939
auto protocol = dyn_cast<ProtocolDecl>(typeDecl->getDeclContext());
940-
if (!protocol)
941-
return;
942940

943941
// If we weren't given a conformance, go look it up.
944942
ProtocolConformance *conformance = nullptr;
945-
if (auto conformanceRef = TypeChecker::conformsToProtocol(
946-
parentTy, protocol, dc,
947-
(ConformanceCheckFlags::InExpression |
948-
ConformanceCheckFlags::SuppressDependencyTracking |
949-
ConformanceCheckFlags::SkipConditionalRequirements))) {
950-
if (conformanceRef->isConcrete())
951-
conformance = conformanceRef->getConcrete();
952-
}
943+
if (protocol)
944+
if (auto conformanceRef = TypeChecker::conformsToProtocol(
945+
parentTy, protocol, dc,
946+
(ConformanceCheckFlags::InExpression |
947+
ConformanceCheckFlags::SuppressDependencyTracking |
948+
ConformanceCheckFlags::SkipConditionalRequirements))) {
949+
if (conformanceRef->isConcrete())
950+
conformance = conformanceRef->getConcrete();
951+
}
953952

954953
// If any errors have occurred, don't bother diagnosing this cross-file
955954
// issue.
@@ -958,7 +957,7 @@ static void maybeDiagnoseBadConformanceRef(DeclContext *dc,
958957
return;
959958

960959
auto diagCode =
961-
(conformance && !conformance->getConditionalRequirementsIfAvailable())
960+
(!protocol || (conformance && !conformance->getConditionalRequirementsIfAvailable()))
962961
? diag::unsupported_recursion_in_associated_type_reference
963962
: diag::broken_associated_type_witness;
964963

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)