Skip to content

[Runtime] Fix printing keypaths with LocalDeclName subscript types. #74635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions lib/Demangling/NodePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3626,6 +3626,17 @@ std::string Demangle::keyPathSourceString(const char *MangledName,
return argumentTypeNames[i];
return std::string("<unknown>");
};
auto getArgumentNodeName = [](NodePointer node) {
if (node->getKind() == Node::Kind::Identifier) {
return std::string(node->getText());
}
if (node->getKind() == Node::Kind::LocalDeclName) {
auto text = node->getChild(1)->getText();
auto index = node->getChild(0)->getIndex() + 1;
return std::string(text) + " #" + std::to_string(index);
}
return std::string("<unknown>");
};
// Multiple arguments case
NodePointer argList = matchSequenceOfKinds(
child, {
Expand All @@ -3644,11 +3655,8 @@ std::string Demangle::keyPathSourceString(const char *MangledName,
if (argumentType->getKind() == Node::Kind::TupleElement) {
argumentType =
argumentType->getChild(0)->getChild(0)->getChild(1);
if (argumentType->getKind() == Node::Kind::Identifier) {
argumentTypeNames.push_back(
std::string(argumentType->getText()));
continue;
}
argumentTypeNames.push_back(getArgumentNodeName(argumentType));
continue;
}
argumentTypeNames.push_back("<Unknown>");
}
Expand All @@ -3663,7 +3671,7 @@ std::string Demangle::keyPathSourceString(const char *MangledName,
});
if (argList != nullptr) {
argumentTypeNames.push_back(
std::string(argList->getChild(0)->getChild(1)->getText()));
getArgumentNodeName(argList->getChild(0)->getChild(1)));
}
}
child = child->getChild(1);
Expand Down
13 changes: 13 additions & 0 deletions test/Interpreter/keypath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,16 @@ do {
// CHECK: 5
print(Test(obj: "Hello").utf8.count)
}

do {
struct S1: Hashable {}
struct S2 {
subscript(param: S1) -> String { "Subscript with private type" }
}

let kp = \S2[S1()]
// CHECK: Subscript with private type
print(S2()[keyPath: kp])
// CHECK: {{\\S2\.subscript\(_: S1 #[0-9]+\)|\S2\.<computed 0x.* \(String\)>}}
print(kp)
}