$ ./perl -wIlib -Mconstant' u=>undef' -e '()=$a{+u} if $a'
Use of uninitialized value at -e line 1.
Well, I didn’t even execute that hash lookup, so why is it warning me
about an uninitialized value?
This is a compile-time optimisation to turn hash keys into shared hash
key scalars (containing precomputed hashes) to speed up key lookup.
It stringifies the hash key at compile time as part of the process.
The value should not be stringified if that would cause observable
difference with tied hashes. Commit
04698ff67 fixed this for refs,
globs and regexps, but missed undef scalars.
This could be considered part of bug #79178.
/* Make the CONST have a shared SV */
svp = cSVOPx_svp(((BINOP*)o)->op_last);
if ((!SvIsCOW(sv = *svp))
- && SvTYPE(sv) < SVt_PVMG && !SvROK(sv)) {
+ && SvTYPE(sv) < SVt_PVMG && SvOK(sv) && !SvROK(sv)) {
key = SvPV_const(sv, keylen);
lexname = newSVpvn_share(key,
SvUTF8(sv) ? -(I32)keylen : (I32)keylen,
tie my %h, "bar";
() = $h{\'foo'};
is ref $key, SCALAR =>
- 'hash keys are not stringified during compilation';
+ 'ref hash keys are not stringified during compilation';
+ use constant u => undef;
+ no warnings 'uninitialized'; # work around unfixed bug #105918
+ () = $h{+u};
+ is $key, undef,
+ 'undef hash keys are not stringified during compilation, either';
}
# Part of RT #85026: Deleting the current iterator in void context does not