Skip to content

Commit 05e0c67

Browse files
committed
Fix implicit local variables in hashes
1 parent 059e04f commit 05e0c67

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/prism/translation/parser/compiler.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,14 @@ def visit_assoc_node(node)
116116
builder.pair_keyword([node.key.unescaped, srange(node.key.location)], visit(node.value))
117117
end
118118
elsif node.value.is_a?(ImplicitNode)
119-
builder.pair_label([node.key.unescaped, srange(node.key.location)])
119+
if (value = node.value.value).is_a?(LocalVariableReadNode)
120+
builder.pair_keyword(
121+
[node.key.unescaped, srange(node.key)],
122+
builder.ident([value.name, srange(node.key.value_loc)]).updated(:lvar)
123+
)
124+
else
125+
builder.pair_label([node.key.unescaped, srange(node.key.location)])
126+
end
120127
elsif node.operator_loc
121128
builder.pair(visit(node.key), token(node.operator_loc), visit(node.value))
122129
elsif node.key.is_a?(SymbolNode) && node.key.opening_loc.nil?

test/prism/parser_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def assert_equal_asts_message(expected_ast, actual_ast)
144144
end
145145

146146
if left.location != right.location
147-
return "expected:\n#{left.inspect}\n#{left.location}\nactual:\n#{right.inspect}\n#{right.location}"
147+
return "expected:\n#{left.inspect}\n#{left.location.inspect}\nactual:\n#{right.inspect}\n#{right.location.inspect}"
148148
end
149149

150150
if left.type == :str && left.children[0] != right.children[0]

0 commit comments

Comments
 (0)