Skip to content

Commit d80cace

Browse files
committed
ASTDemangler: Fix local type lookup
1 parent 0f5233d commit d80cace

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

lib/AST/ASTDemangler.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,16 @@ ASTBuilder::findModule(const Demangle::NodePointer &node) {
399399

400400
Demangle::NodePointer
401401
ASTBuilder::findModuleNode(const Demangle::NodePointer &node) {
402-
if (node->getKind() == Demangle::Node::Kind::Module)
403-
return node;
402+
auto child = node;
403+
while (child->hasChildren() &&
404+
child->getKind() != Demangle::Node::Kind::Module) {
405+
child = child->getFirstChild();
406+
}
404407

405-
if (!node->hasChildren()) return nullptr;
406-
const auto &child = node->getFirstChild();
407-
if (child->getKind() != Demangle::Node::Kind::DeclContext)
408+
if (child->getKind() != Demangle::Node::Kind::Module)
408409
return nullptr;
409410

410-
return findModuleNode(child->getFirstChild());
411+
return child;
411412
}
412413

413414
Optional<ASTBuilder::ForeignModuleKind>

test/TypeDecoder/local_types.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-build-swift -emit-executable %s -g -o %t/local_types -emit-module
4+
// RUN: sed -ne '/\/\/ *DEMANGLE: /s/\/\/ *DEMANGLE: *//p' < %s > %t/input
5+
// RUN: %lldb-moduleimport-test %t/local_types -type-from-mangled=%t/input | %FileCheck %s
6+
7+
func blackHole(_: Any...) {}
8+
9+
func foo() {
10+
struct Outer {
11+
struct Inner { }
12+
struct GenericInner<T> { }
13+
}
14+
15+
do {
16+
let x1 = Outer()
17+
let x2 = Outer.Inner()
18+
let x3 = Outer.GenericInner<Int>()
19+
20+
blackHole(x1, x2, x3)
21+
}
22+
23+
do {
24+
let x1 = Outer.self
25+
let x2 = Outer.Inner.self
26+
let x3 = Outer.GenericInner<Int>.self
27+
28+
blackHole(x1, x2, x3)
29+
}
30+
}
31+
32+
// DEMANGLE: $s11local_types3fooyyF5OuterL_VD
33+
// CHECK: Outer
34+
35+
// DEMANGLE: $s11local_types3fooyyF5OuterL_V5InnerVD
36+
// CHECK: Outer.Inner
37+
38+
// DEMANGLE: $s11local_types3fooyyF5OuterL_V12GenericInnerVy_SiGD
39+
// CHECK: Outer.GenericInner<Int>
40+
41+
// DEMANGLE: $s11local_types3fooyyF5OuterL_VmD
42+
// CHECK: Outer.Type
43+
44+
// DEMANGLE: $s11local_types3fooyyF5OuterL_V5InnerVmD
45+
// CHECK: Outer.Inner.Type
46+
47+
// DEMANGLE: $s11local_types3fooyyF5OuterL_V12GenericInnerVy_SiGmD
48+
// CHECK: Outer.GenericInner<Int>.Type

0 commit comments

Comments
 (0)