Skip to content

Commit

Permalink
Properly destructure procarg0 in parser translation
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Jun 3, 2024
1 parent aee84cf commit 823e931
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
27 changes: 14 additions & 13 deletions lib/prism/translation/parser/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1390,12 +1390,12 @@ def visit_parameters_node(node)

if node.requireds.any?
node.requireds.each do |required|
if required.is_a?(RequiredParameterNode)
params << visit(required)
else
compiler = copy_compiler(in_destructure: true)
params << required.accept(compiler)
end
params <<
if required.is_a?(RequiredParameterNode)
visit(required)
else
required.accept(copy_compiler(in_destructure: true))
end
end
end

Expand All @@ -1404,12 +1404,12 @@ def visit_parameters_node(node)

if node.posts.any?
node.posts.each do |post|
if post.is_a?(RequiredParameterNode)
params << visit(post)
else
compiler = copy_compiler(in_destructure: true)
params << post.accept(compiler)
end
params <<
if post.is_a?(RequiredParameterNode)
visit(post)
else
post.accept(copy_compiler(in_destructure: true))
end
end
end

Expand Down Expand Up @@ -2004,7 +2004,8 @@ def visit_block(call, block)
token(parameters.opening_loc),
if procarg0?(parameters.parameters)
parameter = parameters.parameters.requireds.first
[builder.procarg0(visit(parameter))].concat(visit_all(parameters.locals))
visited = parameter.is_a?(RequiredParameterNode) ? visit(parameter) : parameter.accept(copy_compiler(in_destructure: true))
[builder.procarg0(visited)].concat(visit_all(parameters.locals))
else
visit(parameters)
end,
Expand Down
6 changes: 0 additions & 6 deletions test/prism/ruby/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ class ParserTest < TestCase
"spanning_heredoc.txt",
"spanning_heredoc_newlines.txt",
"unescaping.txt",
"seattlerb/block_decomp_anon_splat_arg.txt",
"seattlerb/block_decomp_arg_splat_arg.txt",
"seattlerb/block_decomp_arg_splat.txt",
"seattlerb/block_decomp_splat.txt",
"seattlerb/block_paren_splat.txt",
"seattlerb/bug190.txt",
"seattlerb/heredoc_nested.txt",
"seattlerb/heredoc_with_carriage_return_escapes_windows.txt",
Expand All @@ -69,7 +64,6 @@ class ParserTest < TestCase
"seattlerb/pctW_lineno.txt",
"seattlerb/regexp_esc_C_slash.txt",
"seattlerb/TestRubyParserShared.txt",
"unparser/corpus/literal/block.txt",
"unparser/corpus/literal/literal.txt",
"unparser/corpus/literal/pattern.txt",
"unparser/corpus/semantic/dstr.txt",
Expand Down

0 comments on commit 823e931

Please sign in to comment.