summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2024-01-16 22:06:39 -0800
committergit <svn-admin@ruby-lang.org>2024-01-17 17:47:34 +0000
commite0d60a833b8baa6305a2027253c1deafe5b5bcba (patch)
tree7f9e4cc33f7b24247a409c3b9971fdd331e4735d
parentbcc4b07cc318df3d5f53f14e36829eeab4066ecc (diff)
[ruby/prism] Fix => ^it
https://github.com/ruby/prism/commit/24a2872b4e
-rw-r--r--prism/prism.c9
-rw-r--r--test/prism/location_test.rb3
2 files changed, 10 insertions, 2 deletions
diff --git a/prism/prism.c b/prism/prism.c
index 0778667f96..3316c09517 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -13602,8 +13602,13 @@ parse_pattern_primitive(pm_parser_t *parser, pm_diagnostic_id_t diag_id) {
parser_lex(parser);
pm_node_t *variable = (pm_node_t *) parse_variable(parser);
if (variable == NULL) {
- PM_PARSER_ERR_TOKEN_FORMAT(parser, parser->previous, PM_ERR_NO_LOCAL_VARIABLE, (int) (parser->previous.end - parser->previous.start), parser->previous.start);
- variable = (pm_node_t *) pm_local_variable_read_node_create(parser, &parser->previous, 0);
+ if (pm_token_is_it(parser->previous.start, parser->previous.end)) {
+ pm_constant_id_t name_id = pm_parser_constant_id_constant(parser, "0it", 3);
+ variable = (pm_node_t *) pm_local_variable_read_node_create_constant_id(parser, &parser->previous, name_id, 0);
+ } else {
+ PM_PARSER_ERR_TOKEN_FORMAT(parser, parser->previous, PM_ERR_NO_LOCAL_VARIABLE, (int) (parser->previous.end - parser->previous.start), parser->previous.start);
+ variable = (pm_node_t *) pm_local_variable_read_node_create(parser, &parser->previous, 0);
+ }
}
return (pm_node_t *) pm_pinned_variable_node_create(parser, &operator, variable);
diff --git a/test/prism/location_test.rb b/test/prism/location_test.rb
index a36f5fe011..bcc357776a 100644
--- a/test/prism/location_test.rb
+++ b/test/prism/location_test.rb
@@ -680,6 +680,9 @@ module Prism
def test_PinnedVariableNode
assert_location(PinnedVariableNode, "bar = 1; foo in ^bar", 16...20, &:pattern)
+ assert_location(PinnedVariableNode, "proc { 1 in ^it }.call(1)", 12...15) do |node|
+ node.receiver.block.body.body.first.pattern
+ end
end
def test_PostExecutionNode