Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parser translator scope issues for implicit hash values #3423

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/prism/translation/parser/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,17 @@ def visit_assoc_node(node)
builder.pair_quoted(token(key.opening_loc), [builder.string_internal([key.unescaped, srange(key.value_loc)])], token(key.closing_loc), visit(node.value))
end
elsif node.value.is_a?(ImplicitNode)
if (value = node.value.value).is_a?(LocalVariableReadNode)
builder.pair_keyword(
[key.unescaped, srange(key)],
builder.ident([value.name, srange(key.value_loc)]).updated(:lvar)
)
value = node.value.value

implicit_value = if value.is_a?(CallNode)
builder.call_method(nil, nil, [value.name, srange(value.message_loc)])
elsif value.is_a?(ConstantReadNode)
builder.const([value.name, srange(key.value_loc)])
else
builder.pair_label([key.unescaped, srange(key.location)])
builder.ident([value.name, srange(key.value_loc)]).updated(:lvar)
end

builder.pair_keyword([key.unescaped, srange(key)], implicit_value)
elsif node.operator_loc
builder.pair(visit(key), token(node.operator_loc), visit(node.value))
elsif key.is_a?(SymbolNode) && key.opening_loc.nil?
Expand Down
Loading