Skip to content

Commit 5350d45

Browse files
committed
[Mangler] Mangle generic typealiases in extensions of nested generics.
1 parent 4f66824 commit 5350d45

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,12 @@ unsigned ASTMangler::appendBoundGenericArgs(DeclContext *dc,
10451045
auto decl = dc->getInnermostDeclarationDeclContext();
10461046
if (!decl) return 0;
10471047

1048+
// For an extension declaration, use the nominal type declaration instead.
1049+
// This is important when extending a nested type, because the generic
1050+
// parameters will line up with the (semantic) nesting of the nominal type.
1051+
if (auto ext = dyn_cast<ExtensionDecl>(decl))
1052+
decl = ext->getAsNominalTypeOrNominalTypeExtensionContext();
1053+
10481054
// Handle the generic arguments of the parent.
10491055
unsigned currentGenericParamIdx =
10501056
appendBoundGenericArgs(decl->getDeclContext(), subs, isFirstArgList);

test/DebugInfo/DumpDeclFromMangledName.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ typealias Patatino<T> = Foo<T>
5151

5252
public struct Outer<T> {
5353
public struct Inner { }
54+
public struct GenericInner<U> { }
5455

5556
public typealias Foo<U> = Outer<U>.Inner
5657

@@ -59,6 +60,14 @@ public struct Outer<T> {
5960
}
6061
}
6162

63+
extension Outer.GenericInner {
64+
public typealias Bar = Int
65+
66+
public func useBar() {
67+
let bar: Bar = 7
68+
}
69+
}
70+
6271
func main() -> Int {
6372
var p : Patatino<Int> = Patatino(23);
6473
return 0

test/DebugInfo/Inputs/decl-reconstr-names.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ $S12DeclReconstr8patatinoSiyF ---> func patatino() -> Int
22
$S12DeclReconstr1SVACycfC ---> init()
33
$S12DeclReconstr8PatatinoaySiGD ---> typealias Patatino<T> = Foo<T>
44
$S12DeclReconstr5OuterV3Fooayx_SiGD ---> Can't resolve decl of $S12DeclReconstr5OuterV3Fooayx_SiGD
5+
$S12DeclReconstr5OuterV12GenericInnerV3Barayx_qd___GD ---> typealias Bar = Int

0 commit comments

Comments
 (0)