diff --git a/t/op/array.t b/t/op/array.t index 75cb3cf631d9..771872a1a361 100644 --- a/t/op/array.t +++ b/t/op/array.t @@ -6,7 +6,7 @@ BEGIN { set_up_inc('.', '../lib'); } -plan (195); +plan (197); # # @foo, @bar, and @ary are also used from tie-stdarray after tie-ing them @@ -707,3 +707,15 @@ fresh_perl_is('my @x;$x[0] = 1;shift @x;$x[22] = 1;$x[25] = 1;','', {}, 'unshifting and growing an array initializes trailing elements'); "We're included by lib/Tie/Array/std.t so we need to return something true"; + +# GH #23447 - ensure that future optimizations don't break behaviour +{ + my @x = "a" .. "d"; + sub f {} + my $y = @x[2, 3, f()]; + is $y, 'd', 'Trailing empty list return in array slice in scalar context'; + + my @i; + $y = @x[2, 3, @i]; + is $y, 'd', 'Empty array final element in array slice in scalar context'; +} diff --git a/t/op/list.t b/t/op/list.t index 30ec3d878c24..3a018d1a4cdd 100644 --- a/t/op/list.t +++ b/t/op/list.t @@ -6,7 +6,7 @@ BEGIN { set_up_inc(qw(. ../lib)); } -plan( tests => 73 ); +plan( tests => 75 ); @foo = (1, 2, 3, 4); cmp_ok($foo[0], '==', 1, 'first elem'); @@ -275,3 +275,14 @@ EOS my $e = "1"; $e = "(1,$e)" for 1..100_000; $e = "() = $e"; eval $e; is $@, "", "SEGV in Perl_list"; } + +# GH #23447 - ensure that future optimizations don't break behaviour +{ + sub f {} + my $y = ("a" .. "d")[2, 3, f()]; + is $y, 'd', 'Trailing empty list return in list slice in scalar context'; + + my @i; + $y = ("a" .. "d")[2, 3, @i]; + is $y, 'd', 'Empty array final element in list slice in scalar context'; +}