Skip to content

Commit 7c46b31

Browse files
committed
Extra tests for array/list slices in scalar context
1 parent ca40375 commit 7c46b31

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

t/op/array.t

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ BEGIN {
66
set_up_inc('.', '../lib');
77
}
88

9-
plan (195);
9+
plan (197);
1010

1111
#
1212
# @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;','',
707707
{}, 'unshifting and growing an array initializes trailing elements');
708708

709709
"We're included by lib/Tie/Array/std.t so we need to return something true";
710+
711+
# GH #23447 - ensure that future optimizations don't break behaviour
712+
{
713+
my @x = "a" .. "d";
714+
sub f {}
715+
my $y = @x[2, 3, f()];
716+
is $y, 'd', 'Trailing empty list return in array slice in scalar context';
717+
718+
my @i;
719+
$y = @x[2, 3, @i];
720+
is $y, 'd', 'Empty array final element in array slice in scalar context';
721+
}

t/op/list.t

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ BEGIN {
66
set_up_inc(qw(. ../lib));
77
}
88

9-
plan( tests => 73 );
9+
plan( tests => 75 );
1010

1111
@foo = (1, 2, 3, 4);
1212
cmp_ok($foo[0], '==', 1, 'first elem');
@@ -275,3 +275,14 @@ EOS
275275
my $e = "1"; $e = "(1,$e)" for 1..100_000; $e = "() = $e"; eval $e;
276276
is $@, "", "SEGV in Perl_list";
277277
}
278+
279+
# GH #23447 - ensure that future optimizations don't break behaviour
280+
{
281+
sub f {}
282+
my $y = ("a" .. "d")[2, 3, f()];
283+
is $y, 'd', 'Trailing empty list return in list slice in scalar context';
284+
285+
my @i;
286+
$y = ("a" .. "d")[2, 3, @i];
287+
is $y, 'd', 'Empty array final element in list slice in scalar context';
288+
}

0 commit comments

Comments
 (0)