Skip to content

Commit 20c767a

Browse files
committed
GSB: Don't forget to concretize conformances when processing a same-type requirement
When merging two type parameters T1 and T2, if T2 had a concrete type and T1 had conformance requirements, we did not "concretize" the conformances. As a result, the conformance requirements were not marked as redundant, which would cause a crash (no assert build) or assertion failure (in an assert build) later on inside rebuildSignatureWithoutRedundantRequirements(). Fixes rdar://problem/79570734.
1 parent 00595c0 commit 20c767a

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,7 +2413,7 @@ void DelayedRequirement::dump(llvm::raw_ostream &out) const {
24132413
case Type:
24142414
case Layout:
24152415
out << ": ";
2416-
break;
2416+
break;
24172417

24182418
case SameType:
24192419
out << " == ";
@@ -5047,6 +5047,9 @@ GenericSignatureBuilder::addSameTypeRequirementBetweenTypeParameters(
50475047
equivClass->concreteTypeConstraints.end(),
50485048
equivClass2->concreteTypeConstraints.begin(),
50495049
equivClass2->concreteTypeConstraints.end());
5050+
5051+
for (const auto &conforms : equivClass->conformsTo)
5052+
(void)resolveConcreteConformance(T1, conforms.first);
50505053
}
50515054

50525055
// Make T1 the representative of T2, merging the equivalence classes.
@@ -5775,9 +5778,9 @@ void GenericSignatureBuilder::ExplicitRequirement::dump(
57755778

57765779
out << getSubjectType();
57775780
if (getKind() == RequirementKind::SameType)
5778-
out << " : ";
5779-
else
57805781
out << " == ";
5782+
else
5783+
out << " : ";
57815784

57825785
if (auto type = rhs.dyn_cast<Type>())
57835786
out << type;

test/Generics/rdar79570734.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-typecheck-verify-swift
2+
// RUN: %target-swift-frontend -typecheck -debug-generic-signatures %s 2>&1 | %FileCheck %s
3+
4+
public protocol P1 {
5+
associatedtype A
6+
}
7+
8+
public protocol P2 {}
9+
10+
public struct S1: P1 {
11+
public typealias A = S2
12+
}
13+
14+
public struct S2: P2 {}
15+
16+
// CHECK-LABEL: Generic signature: <X, Y where X : P1, Y : P2, Y == X.A>
17+
public struct G<X: P1, Y: P2> where Y == X.A {}
18+
19+
// CHECK-LABEL: Generic signature: <X, Y where X == S1, Y == S1.A>
20+
public extension G where X == S1 {}

0 commit comments

Comments
 (0)