Skip to content

Commit 92406b1

Browse files
committed
Fix location of anonymous kwargs
1 parent 7f9075d commit 92406b1

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
@@ -2731,15 +2731,21 @@ unique_ptr<parser::Node> Translator::translate(pm_node_t *node, bool preserveCon
27312731
// This doesn't include `**nil`, which is a `PM_NO_KEYWORDS_PARAMETER_NODE`.
27322732
auto keywordRestParamNode = down_cast<pm_keyword_rest_parameter_node>(node);
27332733

2734+
core::LocOffsets kwrestLoc;
27342735
core::NameRef sorbetName;
27352736
if (auto prismName = keywordRestParamNode->name; prismName != PM_CONSTANT_ID_UNSET) {
27362737
// A named keyword rest parameter, like `def foo(**kwargs)`
27372738
sorbetName = translateConstantName(prismName);
2739+
2740+
// The location doesn't include the `**`, only the splatted expression like `kwargs` in `**kwargs`
2741+
kwrestLoc = core::LocOffsets{location.beginPos() + 2, location.endPos()};
27382742
} else { // An anonymous keyword rest parameter, like `def foo(**)`
27392743
sorbetName = nextUniqueParserName(core::Names::starStar());
2744+
2745+
// This location *does* include the whole `**`.
2746+
kwrestLoc = location;
27402747
}
27412748

2742-
auto kwrestLoc = core::LocOffsets{location.beginPos() + 2, location.endPos()};
27432749
return make_node_with_expr<parser::Kwrestarg>(
27442750
MK::RestParam(kwrestLoc, MK::KeywordArg(kwrestLoc, sorbetName)), kwrestLoc, sorbetName);
27452751
}

0 commit comments

Comments
 (0)