Skip to content

Commit 75bf101

Browse files
committed
IRGen: Also handle nested types inside of extensions
rdar://39648725
1 parent a830acd commit 75bf101

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2829,8 +2829,8 @@ void irgen::emitStructMetadata(IRGenModule &IGM, StructDecl *structDecl) {
28292829
void IRGenerator::noteUseOfAnyParentTypeMetadata(NominalTypeDecl *type) {
28302830
// If this is a nested type we also potentially might need the outer types.
28312831
auto *declCtxt = type->getDeclContext();
2832-
assert(declCtxt);
2833-
auto *parentNominalDecl = dyn_cast_or_null<NominalTypeDecl>(declCtxt);
2832+
auto *parentNominalDecl =
2833+
declCtxt->getAsNominalTypeOrNominalTypeExtensionContext();
28342834
if (!parentNominalDecl)
28352835
return;
28362836

test/multifile/Inputs/nested_types_defs.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ struct Outer3 {
1313
}
1414
}
1515

16+
struct Outer4 {}
17+
18+
extension Outer4 {
19+
struct InnerExtension {}
20+
}

test/multifile/nested_types.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22

33
// Make sure we generate the outer metadata.
44

5-
// CHECK-DAG: @"$S4test6Outer3VMf" = internal constant {{.*}} @"$SytWV"{{.*}}@"$S4test6Outer3VMn"
5+
// CHECK-DAG: @"$S4test5OuterVMf" = internal constant {{.*}} @"$SytWV"{{.*}}@"$S4test5OuterVMn"
66
// CHECK-DAG: @"$S4test6Outer2VMf" = internal constant {{.*}} @"$SytWV"{{.*}}@"$S4test6Outer2VMn"
77
// CHECK-DAG: @"$S4test6Outer3VMf" = internal constant {{.*}} @"$SytWV"{{.*}}@"$S4test6Outer3VMn"
8+
// CHECK-DAG: @"$S4test6Outer4VMf" = internal constant {{.*}} @"$SytWV"{{.*}}@"$S4test6Outer4VMn"
89

910
class C<T> { }
1011

1112
struct Y {
1213
let x:C<Outer.Inner>
1314
let y:C<Outer2.InnerE>
1415
let z:C<Outer3.InnerC>
16+
let w:C<Outer4.InnerExtension>
1517
}
1618

1719
public func test() {
18-
var c = Y(x: C<Outer.Inner>(), y: C<Outer2.InnerE>(), z: C<Outer3.InnerC>())
20+
var c = Y(x: C<Outer.Inner>(), y: C<Outer2.InnerE>(), z: C<Outer3.InnerC>(),
21+
w: C<Outer4.InnerExtension>())
1922

2023
print("a \(c)")
2124
}

test/multifile/nested_types/main.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ struct Y {
88
let x:C<Outer.Inner>
99
let y:C<Outer2.InnerE>
1010
let z:C<Outer3.InnerC>
11+
let w:C<Outer4.InnerExtension>
1112
}
1213

1314
func test() {
14-
var c = Y(x: C<Outer.Inner>(), y: C<Outer2.InnerE>(), z: C<Outer3.InnerC>())
15+
var c = Y(x: C<Outer.Inner>(), y: C<Outer2.InnerE>(), z: C<Outer3.InnerC>(), w: C<Outer4.InnerExtension>())
1516

1617
print("a \(c)")
1718
}
1819

19-
// CHECK: a Y(x: a.C<a.Outer.Inner>, y: a.C<a.Outer2.InnerE>, z: a.C<a.Outer3.InnerC>)
20+
// CHECK: a Y(x: a.C<a.Outer.Inner>, y: a.C<a.Outer2.InnerE>, z: a.C<a.Outer3.InnerC>, w: a.C<a.Outer4.InnerExtension>)
2021
test()

0 commit comments

Comments
 (0)