summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-03-06 15:59:43 -0500
committergit <svn-admin@ruby-lang.org>2024-03-06 21:37:26 +0000
commit4b5fc916172b167970e5af6cdec5d1541ca26b41 (patch)
treeeda2d2e85ee6d1d96f9518cce6ec656b71a15b21
parent38a4b5c1fad4790c8170112e9a97bf165b48cdbd (diff)
[ruby/prism] Fix implicit local variables in hashes
https://github.com/ruby/prism/commit/05e0c6792c
-rw-r--r--lib/prism/translation/parser/compiler.rb9
-rw-r--r--test/prism/parser_test.rb2
2 files changed, 9 insertions, 2 deletions
diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb
index e54ee1dbf5..4ca706c764 100644
--- a/lib/prism/translation/parser/compiler.rb
+++ b/lib/prism/translation/parser/compiler.rb
@@ -116,7 +116,14 @@ module Prism
builder.pair_keyword([node.key.unescaped, srange(node.key.location)], visit(node.value))
end
elsif node.value.is_a?(ImplicitNode)
- builder.pair_label([node.key.unescaped, srange(node.key.location)])
+ if (value = node.value.value).is_a?(LocalVariableReadNode)
+ builder.pair_keyword(
+ [node.key.unescaped, srange(node.key)],
+ builder.ident([value.name, srange(node.key.value_loc)]).updated(:lvar)
+ )
+ else
+ builder.pair_label([node.key.unescaped, srange(node.key.location)])
+ end
elsif node.operator_loc
builder.pair(visit(node.key), token(node.operator_loc), visit(node.value))
elsif node.key.is_a?(SymbolNode) && node.key.opening_loc.nil?
diff --git a/test/prism/parser_test.rb b/test/prism/parser_test.rb
index 61f1b737dc..67051289cb 100644
--- a/test/prism/parser_test.rb
+++ b/test/prism/parser_test.rb
@@ -144,7 +144,7 @@ module Prism
end
if left.location != right.location
- return "expected:\n#{left.inspect}\n#{left.location}\nactual:\n#{right.inspect}\n#{right.location}"
+ return "expected:\n#{left.inspect}\n#{left.location.inspect}\nactual:\n#{right.inspect}\n#{right.location.inspect}"
end
if left.type == :str && left.children[0] != right.children[0]