Commit | Line | Data |
24d0fc42 |
1 | #!perl -w |
2 | use strict; |
3 | |
4 | require './test.pl'; |
5 | |
6 | plan (tests => 8); |
7 | no warnings 'deprecated'; |
8 | |
9 | # Bug #27024 |
10 | { |
11 | # this used to segfault (because $[=1 is optimized away to a null block) |
12 | my $x; |
13 | $[ = 1 while $x; |
14 | pass('#27204'); |
15 | $[ = 0; # restore the original value for less side-effects |
16 | } |
17 | |
18 | # [perl #36313] perl -e "1for$[=0" crash |
19 | { |
20 | my $x; |
21 | $x = 1 for ($[) = 0; |
22 | pass('optimized assignment to $[ used to segfault in list context'); |
23 | if ($[ = 0) { $x = 1 } |
24 | pass('optimized assignment to $[ used to segfault in scalar context'); |
25 | $x = ($[=2.4); |
26 | is($x, 2, 'scalar assignment to $[ behaves like other variables'); |
27 | $x = (($[) = 0); |
28 | is($x, 1, 'list assignment to $[ behaves like other variables'); |
29 | $x = eval q{ ($[, $x) = (0) }; |
30 | like($@, qr/That use of \$\[ is unsupported/, |
31 | 'cannot assign to $[ in a list'); |
32 | eval q{ ($[) = (0, 1) }; |
33 | like($@, qr/That use of \$\[ is unsupported/, |
34 | 'cannot assign list of >1 elements to $['); |
35 | eval q{ ($[) = () }; |
36 | like($@, qr/That use of \$\[ is unsupported/, |
37 | 'cannot assign list of <1 elements to $['); |
38 | } |