Skip to content

Commit c84553c

Browse files
committed
SIL: Fix crash when enum is nested inside a fully-constrained extension
Fixes <https://bugs.swift.org/browse/SR-10023>.
1 parent 56a73c9 commit c84553c

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
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);

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() {

0 commit comments

Comments
 (0)