Skip to content

Commit 1ef4c23

Browse files
authored
Merge pull request swiftlang#23037 from slavapestov/enum-constrained-extension-fix
Fix crash when enum is nested inside a fully-constrained extension
2 parents 1733182 + c47683c commit 1ef4c23

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

lib/SIL/TypeLowering.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,8 +1840,15 @@ CanAnyFunctionType TypeConverter::makeConstantInterfaceType(SILDeclRef c) {
18401840
return getFunctionInterfaceTypeWithCaptures(funcTy, func);
18411841
}
18421842

1843-
case SILDeclRef::Kind::EnumElement:
1844-
return cast<AnyFunctionType>(vd->getInterfaceType()->getCanonicalType());
1843+
case SILDeclRef::Kind::EnumElement: {
1844+
auto funcTy = cast<AnyFunctionType>(
1845+
vd->getInterfaceType()->getCanonicalType());
1846+
auto sig = getEffectiveGenericSignature(vd->getDeclContext());
1847+
return CanAnyFunctionType::get(sig,
1848+
funcTy->getParams(),
1849+
funcTy.getResult(),
1850+
funcTy->getExtInfo());
1851+
}
18451852

18461853
case SILDeclRef::Kind::Allocator: {
18471854
auto *cd = cast<ConstructorDecl>(vd);

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,8 @@ static void diagnoseConformanceImpliedByConditionalConformance(
16231623
ProtocolConformance *MultiConformanceChecker::
16241624
checkIndividualConformance(NormalProtocolConformance *conformance,
16251625
bool issueFixit) {
1626+
PrettyStackTraceConformance trace(TC.Context, "type-checking", conformance);
1627+
16261628
std::vector<ValueDecl*> revivedMissingWitnesses;
16271629
switch (conformance->getState()) {
16281630
case ProtocolConformanceState::Incomplete:
@@ -4392,8 +4394,6 @@ void TypeChecker::useBridgedNSErrorConformances(DeclContext *dc, Type type) {
43924394
}
43934395

43944396
void TypeChecker::checkConformance(NormalProtocolConformance *conformance) {
4395-
PrettyStackTraceConformance trace(Context, "type-checking", conformance);
4396-
43974397
MultiConformanceChecker checker(*this);
43984398
checker.addConformance(conformance);
43994399
checker.checkAllConformances();

test/SILGen/constrained_extensions.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ extension Array where Element == AnyObject {
212212
// CHECK-LABEL: sil hidden [ossa] @$sSa22constrained_extensionsyXlRszlE12DerivedClassCfE : $@convention(method) (@guaranteed Array<AnyObject>.DerivedClass) -> ()
213213
var e: Element? = nil
214214
}
215+
216+
enum NestedEnum {
217+
case hay
218+
case grain
219+
220+
func makeHay() -> NestedEnum {
221+
return .hay
222+
}
223+
}
215224
}
216225

217226
func referenceNestedTypes() {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
3+
protocol P1 {
4+
associatedtype A2 : P2 where A2.A1 == Self
5+
}
6+
7+
protocol P2 {
8+
associatedtype A1 : P1 where A1.A2 == Self
9+
var property: Int { get }
10+
}
11+
12+
extension P2 {
13+
var property: Int { return 0 }
14+
}
15+
16+
class C1 : P1 {
17+
class A2 : P2 {
18+
typealias A1 = C1
19+
}
20+
}

0 commit comments

Comments
 (0)