Skip to content

Commit c8aee3c

Browse files
authored
Merge pull request #74665 from mikeash/anykeypath-printing-private-subscript-type-6.0
[6.0][Runtime] Fix printing keypaths with LocalDeclName subscript types.
2 parents 69ec03c + 6c4fe27 commit c8aee3c

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

lib/Demangling/NodePrinter.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3617,6 +3617,17 @@ std::string Demangle::keyPathSourceString(const char *MangledName,
36173617
return argumentTypeNames[i];
36183618
return std::string("<unknown>");
36193619
};
3620+
auto getArgumentNodeName = [](NodePointer node) {
3621+
if (node->getKind() == Node::Kind::Identifier) {
3622+
return std::string(node->getText());
3623+
}
3624+
if (node->getKind() == Node::Kind::LocalDeclName) {
3625+
auto text = node->getChild(1)->getText();
3626+
auto index = node->getChild(0)->getIndex() + 1;
3627+
return std::string(text) + " #" + std::to_string(index);
3628+
}
3629+
return std::string("<unknown>");
3630+
};
36203631
// Multiple arguments case
36213632
NodePointer argList = matchSequenceOfKinds(
36223633
child, {
@@ -3635,11 +3646,8 @@ std::string Demangle::keyPathSourceString(const char *MangledName,
36353646
if (argumentType->getKind() == Node::Kind::TupleElement) {
36363647
argumentType =
36373648
argumentType->getChild(0)->getChild(0)->getChild(1);
3638-
if (argumentType->getKind() == Node::Kind::Identifier) {
3639-
argumentTypeNames.push_back(
3640-
std::string(argumentType->getText()));
3641-
continue;
3642-
}
3649+
argumentTypeNames.push_back(getArgumentNodeName(argumentType));
3650+
continue;
36433651
}
36443652
argumentTypeNames.push_back("<Unknown>");
36453653
}
@@ -3654,7 +3662,7 @@ std::string Demangle::keyPathSourceString(const char *MangledName,
36543662
});
36553663
if (argList != nullptr) {
36563664
argumentTypeNames.push_back(
3657-
std::string(argList->getChild(0)->getChild(1)->getText()));
3665+
getArgumentNodeName(argList->getChild(0)->getChild(1)));
36583666
}
36593667
}
36603668
child = child->getChild(1);

test/Interpreter/keypath.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,16 @@ do {
149149
// CHECK: 5
150150
print(Test(obj: "Hello").utf8.count)
151151
}
152+
153+
do {
154+
struct S1: Hashable {}
155+
struct S2 {
156+
subscript(param: S1) -> String { "Subscript with private type" }
157+
}
158+
159+
let kp = \S2[S1()]
160+
// CHECK: Subscript with private type
161+
print(S2()[keyPath: kp])
162+
// CHECK: {{\\S2\.subscript\(_: S1 #[0-9]+\)|\S2\.<computed 0x.* \(String\)>}}
163+
print(kp)
164+
}

0 commit comments

Comments
 (0)