Skip to content

Commit dd99ef8

Browse files
committed
don't blame $x if reftype($x)/refaddr($x) is undef
When the "Use of uninitialized value" warning tries to find the source of the problem, it skips over builtin::reftype/builtin::refaddr operations and blames their arguments: $ perl -wE 'my $x = 42; $_ = reftype($x) eq ""' Use of uninitialized value $x in string eq at -e line 1. $ perl -wE 'my $x = 42; $_ = refaddr($x) eq ""' Use of uninitialized value $x in string eq at -e line 1. This is wrong because $x is clearly defined. This patch teaches S_find_uninit_var that reftype/refaddr can return undef even if their arguments are perfectly defined. Fixes #19273.
1 parent bac7097 commit dd99ef8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

sv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17532,6 +17532,8 @@ S_find_uninit_var(pTHX_ const OP *const obase, const SV *const uninit_sv,
1753217532
case OP_SYSOPEN:
1753317533
case OP_SYSSEEK:
1753417534
case OP_SPLICE: /* scalar splice(@x, $i, 0) ==> undef */
17535+
case OP_REFADDR:
17536+
case OP_REFTYPE:
1753517537
match = 1;
1753617538
goto do_op;
1753717539

t/lib/warnings/9uninit

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,3 +2303,12 @@ Use of uninitialized value shift(@ARGV) in lc at - line 26.
23032303
Use of uninitialized value shift() in lc at - line 27.
23042304
Use of uninitialized value pop(@ARGV) in lc at - line 28.
23052305
Use of uninitialized value pop() in lc at - line 29.
2306+
########
2307+
# GH #19273
2308+
use warnings 'uninitialized';
2309+
my $x = 'fine';
2310+
$_ = builtin::refaddr($x) == 1;
2311+
$_ = builtin::reftype($x) eq '';
2312+
EXPECT
2313+
Use of uninitialized value in numeric eq (==) at - line 4.
2314+
Use of uninitialized value in string eq at - line 5.

0 commit comments

Comments
 (0)