Skip to content

Commit 004a040

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

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

t/op/array.t

Lines changed: 11 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,13 @@ 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"; sub f {} my $y = @x[2, 3, f()];
714+
is $y, d, 'Non-returning final sub element in array slice in scalar context';
715+
716+
my @i;
717+
$y = @x[2, 3, @i];
718+
is $y, d, 'Empty array final element in array slice in scalar context';
719+
}

t/op/list.t

Lines changed: 11 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,13 @@ 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 {} my $y = ("a" .. "d")[2, 3, f()];
282+
is $y, d, 'Non-returning final sub element in list slice in scalar context';
283+
284+
my @i;
285+
$y = ("a" .. "d")[2, 3, @i];
286+
is $y, d, 'Empty array final element in list slice in scalar context';
287+
}

0 commit comments

Comments
 (0)