diff options
author | Lukas Mai <lukasmai.403@gmail.com> | 2023-03-20 15:39:42 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2023-03-24 07:55:49 +0800 |
commit | 095fd90e6ff7791c309ef4175edebb2295e5ea04 (patch) | |
tree | 8df2f19671c2d461e9a858d406a9cb7482502a10 /t | |
parent | fe937a9fe468d3821699cc22af3e9cdcadf2608a (diff) | |
download | perl-095fd90e6ff7791c309ef4175edebb2295e5ea04.tar.gz |
report uninit variable name even in optimized cases
Several cases that used to be simple assignment ops with lexical
variables have been optimized in some way:
- $foo = undef is now a single OP_UNDEF with special flags
- $foo = ... is now a single OP_PADSV_STORE
- $foo[0] = ... is now a single OP_AELEMFASTLEX_STORE
This is mostly transparent to users, except for "Use of uninitialized
value" warnings, which previously mentioned the name of the undefined
variable, but don't do so anymore in blead.
This commit teaches find_uninit_var() about the new ops, so error
messages for these ops can mention variable names again.
Fixes #20945.
Diffstat (limited to 't')
-rw-r--r-- | t/lib/warnings/9uninit | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/t/lib/warnings/9uninit b/t/lib/warnings/9uninit index 0ceb0d240a..c889f22ffa 100644 --- a/t/lib/warnings/9uninit +++ b/t/lib/warnings/9uninit @@ -2216,3 +2216,33 @@ EXPECT Use of uninitialized value in regexp compilation at - line 5. Use of uninitialized value in regexp compilation at - line 5. Use of uninitialized value $x in regexp compilation at - line 5. +######## +# GH #20945 +use warnings 'uninitialized'; +my ($v, $x, $y, @arr, %hash); + +$v = ($x = undef) + 1; +$v = 1 + ($x = undef); +$v = ($x = $y) - 1; +$v = 1 - ($x = $y); +$v = ($x = []->[0]) + ($y = [1]->[0]); +$v = ($x = [1]->[0]) + ($y = []->[0]); +$v = ($x = ()) * 2; +(my $z = $y) =~ s/a/b/; +($arr[0] = undef) =~ s/a/b/; +($arr[0] = $z) =~ s/a/b/; +($hash{foo} = undef) =~ s/a/b/; +($hash{foo} = $z) =~ s/a/b/; +EXPECT +Use of uninitialized value $x in addition (+) at - line 5. +Use of uninitialized value $x in addition (+) at - line 6. +Use of uninitialized value $x in subtraction (-) at - line 7. +Use of uninitialized value $x in subtraction (-) at - line 8. +Use of uninitialized value $x in addition (+) at - line 9. +Use of uninitialized value $y in addition (+) at - line 10. +Use of uninitialized value $x in multiplication (*) at - line 11. +Use of uninitialized value $z in substitution (s///) at - line 12. +Use of uninitialized value $arr[0] in substitution (s///) at - line 13. +Use of uninitialized value $arr[0] in substitution (s///) at - line 14. +Use of uninitialized value $hash{"foo"} in substitution (s///) at - line 15. +Use of uninitialized value $hash{"foo"} in substitution (s///) at - line 16. |