Repository: ruby/prism
Pull request #2864 (2024-06-03 21:31:33)

Revert "Revert "Properly destructure procarg0 in parser translation""
Reverts ruby/prism#2863


Patch:
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 8f9251af..ccc138f1 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -244,7 +244,8 @@ jobs:
       with:
         ruby-version: head
         bundler-cache: true
-    - run: bundle exec rake build
+    - run: bundle config --local frozen false
+    - run: bundle exec rake build:dev
     - uses: actions/upload-artifact@v4
       with:
         name: gem-package
diff --git a/Rakefile b/Rakefile
index 95712638..365509de 100644
--- a/Rakefile
+++ b/Rakefile
@@ -59,3 +59,17 @@ Prism::Template::TEMPLATES.each do |filepath|
     Prism::Template.render(t.name)
   end
 end
+
+namespace :build do
+  task :dev_version_set do
+    filepath = File.expand_path("prism.gemspec", __dir__)
+    File.write(filepath, File.read(filepath).sub(/spec\.version = ".+?"/, %Q{spec.version = "9999.9.9"}))
+  end
+
+  task :dev_version_clear do
+    sh "git checkout -- prism.gemspec Gemfile.lock"
+  end
+
+  desc "Build a development version of the gem"
+  task dev: ["build:dev_version_set", "build", "build:dev_version_clear"]
+end
diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb
index 816c8841..df5917ab 100644
--- a/lib/prism/translation/parser/compiler.rb
+++ b/lib/prism/translation/parser/compiler.rb
@@ -1390,12 +1390,12 @@ module Prism
 
           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
 
@@ -1404,12 +1404,12 @@ module Prism
 
           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
 
@@ -2004,7 +2004,8 @@ module Prism
                   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,


Test patch:
diff --git a/rakelib/test.rake b/rakelib/test.rake
index 0198659b..73e1b411 100644
--- a/rakelib/test.rake
+++ b/rakelib/test.rake
@@ -26,6 +26,7 @@ end
 
 namespace :test do
   if have_memcheck
+    RubyMemcheck.config(use_only_ruby_free_at_exit: false)
     RubyMemcheck::TestTask.new(valgrind_internal: :compile, &config)
 
     # Hide test:valgrind_internal from rake -T
diff --git a/test/prism/ruby/parser_test.rb b/test/prism/ruby/parser_test.rb
index d5787a0c..d0e3288d 100644
--- a/test/prism/ruby/parser_test.rb
+++ b/test/prism/ruby/parser_test.rb
@@ -52,11 +52,6 @@ module Prism
       "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",
@@ -69,7 +64,6 @@ module Prism
       "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",