From 296782ab60e63fe825461a199369c5dd8505c2b7 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Tue, 4 Jul 2023 10:45:29 -0400 Subject: YJIT: Fix autosplat miscomp for blocks with optionals (#8006) * YJIT: Fix autosplat miscomp for blocks with optionals When passing an array as the sole argument to `yield`, and the yieldee takes more than 1 optional parameter, the array is expanded similar to `*array` splat calls. This is called "autosplat" in `setup_parameters_complex()`. Previously, YJIT did not detect this autosplat condition. It passed the array without expanding it, deviating from interpreter behavior. Detect this conditon and refuse to compile it. Fixes: Shopify/yjit#313 * RJIT: Fix autosplat miscomp for blocks with optionals This is mirrors the same issue as YJIT. See previous commit. --- bootstraptest/test_yjit.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'bootstraptest') diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index a6525e7af9..8be24cfdb4 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -1,3 +1,13 @@ +# Regression test for yielding with autosplat to block with +# optional parameters. https://github.com/Shopify/yjit/issues/313 +assert_equal '[:a, :b, :a, :b]', %q{ + def yielder(arg) = yield(arg) + yield(arg) + + yielder([:a, :b]) do |c = :c, d = :d| + [c, d] + end +} + # Regression test for GC mishap while doing shape transition assert_equal '[:ok]', %q{ # [Bug #19601] -- cgit v1.2.3