Skip to content

Commit 8df0d8e

Browse files
committed
ASTDemangler: Fix import-as-member types
When an enum is imported as an error, the imported type itself becomes a nested type 'Code' of its wrapper type, so you get a type like 'MyError.Code'. However in the mangling grammar the type is a child of a module and not another type. This was tripping up TypeDecoder, which would check parent types for validity and throw out the demangling since it looked invalid. However since this case really is valid, just skip the whole parent type mess when the type is imported and non-generic.
1 parent 21f37d7 commit 8df0d8e

File tree

6 files changed

+76
-2
lines changed

6 files changed

+76
-2
lines changed

lib/AST/ASTDemangler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ Type ASTBuilder::createNominalType(NominalTypeDecl *decl, Type parent) {
7979
if (decl->getGenericParams())
8080
return Type();
8181

82+
// Imported types can be renamed to be members of other (non-generic)
83+
// types, but the mangling does not have a parent type. Just use the
84+
// declared type directly in this case and skip the parent check below.
85+
if (decl->hasClangNode() && !decl->isGenericContext())
86+
return decl->getDeclaredType();
87+
8288
// Validate the parent type.
8389
if (!validateNominalParent(decl, parent))
8490
return Type();

test/Inputs/custom-modules/module.map

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
module ObjCRuntimeVisible {
22
header "ObjCRuntimeVisible.h"
33
}
4+
5+
module ErrorEnums {
6+
header "ErrorEnums.h"
7+
}

test/RemoteAST/Inputs/custom-modules/module.modulemap

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/RemoteAST/foreign_types.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-remoteast-test-with-sdk -I %S/../ClangImporter/Inputs/custom-modules -I %S/Inputs/custom-modules %s | %FileCheck %s
1+
// RUN: %target-swift-remoteast-test-with-sdk -I %S/../ClangImporter/Inputs/custom-modules -I %S/../Inputs/custom-modules %s | %FileCheck %s
22

33
// REQUIRES: swift-remoteast-test
44
// REQUIRES: objc_interop

test/TypeDecoder/foreign_types.swift

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-build-swift -I %S/../ClangImporter/Inputs/custom-modules -I %S/../Inputs/custom-modules -emit-executable -emit-module %s -g -o %t/foreign_types
4+
// RUN: sed -ne '/\/\/ *DEMANGLE: /s/\/\/ *DEMANGLE: *//p' < %s > %t/input
5+
// RUN: %lldb-moduleimport-test-with-sdk %t/foreign_types -type-from-mangled=%t/input | %FileCheck %s
6+
7+
// REQUIRES: objc_interop
8+
9+
import Foundation
10+
import CoreCooling
11+
import ErrorEnums
12+
13+
/*
14+
do {
15+
let x1 = CCRefrigeratorCreate(kCCPowerStandard)
16+
let x2 = MyError.good
17+
let x3 = MyError.Code.good
18+
let x4 = RenamedError.good
19+
let x5 = RenamedError.Code.good
20+
let x6 = Wrapper.MemberEnum.A
21+
let x7 = WrapperByAttribute(0)
22+
}
23+
24+
do {
25+
let x1 = CCRefrigerator.self
26+
let x2 = MyError.self
27+
let x3 = MyError.Code.self
28+
let x4 = RenamedError.self
29+
let x5 = RenamedError.Code.self
30+
let x6 = Wrapper.MemberEnum.self
31+
let x7 = WrapperByAttribute.self
32+
}
33+
*/
34+
35+
// DEMANGLE: $sSo17CCRefrigeratorRefaD
36+
// DEMANGLE: $sSo7MyErrorVD
37+
// DEMANGLE: $sSo7MyErrorLeVD
38+
// DEMANGLE: $sSo14MyRenamedErrorVD
39+
// DEMANGLE: $sSo14MyRenamedErrorLeVD
40+
// DEMANGLE: $sSo12MyMemberEnumVD
41+
// DEMANGLE: $sSo18WrapperByAttributeaD
42+
43+
// CHECK: CCRefrigerator
44+
// CHECK: MyError.Code
45+
// CHECK: MyError
46+
// CHECK: RenamedError.Code
47+
// CHECK: RenamedError
48+
// CHECK: Wrapper.MemberEnum
49+
// CHECK: WrapperByAttribute
50+
51+
// DEMANGLE: $sSo17CCRefrigeratorRefamD
52+
// DEMANGLE: $sSo7MyErrorVmD
53+
// DEMANGLE: $sSC7MyErrorLeVmD
54+
// DEMANGLE: $sSo14MyRenamedErrorVmD
55+
// DEMANGLE: $sSC14MyRenamedErrorLeVmD
56+
// DEMANGLE: $sSo12MyMemberEnumVmD
57+
// DEMANGLE: $sSo18WrapperByAttributeamD
58+
59+
// CHECK: CCRefrigerator.Type
60+
// CHECK: MyError.Code.Type
61+
// CHECK: MyError.Type
62+
// CHECK: RenamedError.Code.Type
63+
// CHECK: RenamedError.Type
64+
// CHECK: Wrapper.MemberEnum.Type
65+
// CHECK: WrapperByAttribute.Type

0 commit comments

Comments
 (0)