Skip to content

Commit 1731a48

Browse files
committed
ASTDemangler: Imported typedefs can be nested inside other types
1 parent e5a5ec4 commit 1731a48

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

include/swift/Demangling/TypeDecoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class TypeDecoder {
301301
if (!decodeMangledTypeDecl(Node, typeDecl, parent, typeAlias))
302302
return BuiltType();
303303

304-
if (typeAlias && Node->getKind() == NodeKind::TypeAlias)
304+
if (typeAlias)
305305
return Builder.createTypeAliasType(typeDecl, parent);
306306

307307
return Builder.createNominalType(typeDecl, parent);

lib/AST/ASTDemangler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ Type ASTBuilder::createTypeAliasType(GenericTypeDecl *decl, Type parent) {
126126
if (aliasDecl->getGenericParams())
127127
return Type();
128128

129+
// Imported types can be renamed to be members of other (non-generic)
130+
// types, but the mangling does not have a parent type. Just use the
131+
// declared type directly in this case and skip the parent check below.
132+
if (aliasDecl->hasClangNode() && !aliasDecl->isGenericContext())
133+
return aliasDecl->getDeclaredInterfaceType();
134+
129135
// Validate the parent type.
130136
if (!validateParentType(aliasDecl, parent))
131137
return Type();

test/TypeDecoder/objc_classes.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ do {
1818
let x2: NSFastEnumeration = x1
1919
let x3: OurObjCProtocol = OurObjCClass()
2020
let x4: NSCache = NSCache<NSNumber, NSString>()
21+
let x5: PropertyListSerialization.WriteOptions = 0
2122

22-
blackHole(x1, x2, x3, x4)
23+
blackHole(x1, x2, x3, x4, x5)
2324
}
2425

2526
do {
2627
let x1: NSSet.Type = NSSet.self
2728
let x2: NSFastEnumeration.Type = x1
2829
let x3: OurObjCProtocol.Type = OurObjCClass.self
2930
let x4: NSCache.Type = NSCache<NSNumber, NSString>.self
31+
let x5: PropertyListSerialization.WriteOptions = 0
3032

31-
blackHole(x1, x2, x3, x4)
33+
blackHole(x1, x2, x3, x4, x5)
3234
}
3335

3436
do {
@@ -42,17 +44,20 @@ do {
4244
// DEMANGLE: $sSo17NSFastEnumeration_pD
4345
// DEMANGLE: $s12objc_classes15OurObjCProtocol_pD
4446
// DEMANGLE: $sSo7NSCacheCySo8NSNumberCSo8NSStringCGD
47+
// DEMANGLE: $sSo26NSPropertyListWriteOptionsaD
4548

4649
// CHECK: NSSet
4750
// CHECK: NSFastEnumeration
4851
// CHECK: OurObjCProtocol
4952
// CHECK: NSCache<NSNumber, NSString>
53+
// CHECK: PropertyListSerialization.WriteOptions
5054

5155
// DEMANGLE: $sSo5NSSetCmD
5256
// DEMANGLE: $sSo5NSSetCXMTD
5357
// DEMANGLE: $sSo17NSFastEnumeration_pXpD
5458
// DEMANGLE: $s12objc_classes15OurObjCProtocol_pXpD
5559
// DEMANGLE: $sSo7NSCacheCySo8NSNumberCSo8NSStringCGmD
60+
// DEMANGLE: $sSo26NSPropertyListWriteOptionsamD
5661

5762
// CHECK: NSSet.Type
5863
// CHECK: @thick NSSet.Type
@@ -62,6 +67,8 @@ do {
6267

6368
// CHECK: NSCache<NSNumber, NSString>.Type
6469

70+
// CHECK: PropertyListSerialization.WriteOptions.Type
71+
6572
// DEMANGLE: $sSo17NSFastEnumeration_pmD
6673
// DEMANGLE: $s12objc_classes15OurObjCProtocol_pmD
6774

0 commit comments

Comments
 (0)