Skip to content

Commit 09153e6

Browse files
committed
Fix location of anonymous kwargs
1 parent fe8c0f6 commit 09153e6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

parser/prism/Translator.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2781,15 +2781,21 @@ unique_ptr<parser::Node> Translator::translate(pm_node_t *node, bool preserveCon
27812781
// This doesn't include `**nil`, which is a `PM_NO_KEYWORDS_PARAMETER_NODE`.
27822782
auto keywordRestParamNode = down_cast<pm_keyword_rest_parameter_node>(node);
27832783

2784+
core::LocOffsets kwrestLoc;
27842785
core::NameRef sorbetName;
27852786
if (auto prismName = keywordRestParamNode->name; prismName != PM_CONSTANT_ID_UNSET) {
27862787
// A named keyword rest parameter, like `def foo(**kwargs)`
27872788
sorbetName = translateConstantName(prismName);
2789+
2790+
// The location doesn't include the `**`, only the splatted expression like `kwargs` in `**kwargs`
2791+
kwrestLoc = core::LocOffsets{location.beginPos() + 2, location.endPos()};
27882792
} else { // An anonymous keyword rest parameter, like `def foo(**)`
27892793
sorbetName = nextUniqueParserName(core::Names::starStar());
2794+
2795+
// This location *does* include the whole `**`.
2796+
kwrestLoc = location;
27902797
}
27912798

2792-
auto kwrestLoc = core::LocOffsets{location.beginPos() + 2, location.endPos()};
27932799
return make_node_with_expr<parser::Kwrestarg>(
27942800
MK::RestParam(kwrestLoc, MK::KeywordArg(kwrestLoc, sorbetName)), kwrestLoc, sorbetName);
27952801
}

0 commit comments

Comments
 (0)