Skip to content

Commit

Permalink
Don’t trigger warnings for qq"@Builtin"
Browse files Browse the repository at this point in the history
Built-in arrays should not be giving warnings about possible unin-
tended interpolation (which happens with nonexistent arrays).

Some built-in variables do not exist if they are not needed, but perl
will generally pretend that they did already exist whenever they are
fetched.  It is such variables that trigger this warning erroneously:

$ ./miniperl -we 'sub dump_isa { warn "@isa" } @isa = ("foo","bar"); dump_isa'
Possible unintended interpolation of @isa in string at -e line 1.
foo bar at -e line 1.

I discovered this when writing a test for @db::args, using -w.
warnings.pm uses @db::args, so ‘use warnings’ code won’t get the warn-
ing, but code using -w gets it:

$ ./miniperl -we 'sub foo { package DB { () = caller 0 } print "@db::args\n" } foo(1..3);'
Possible unintended interpolation of @db::args in string at -e line 1.
1 2 3

The code in toke.c that decides whether this warning should take place
needs to supply the GV_ADDMG flag to gv_fetchpvn_flags, making it one
of the code paths that engages in the pretence mentioned above.

That code already had an explicit exception for @+ and @-.  This com-
mit removes it as being no longer necessary.
  • Loading branch information
Father Chrysostomos committed Jul 31, 2016
1 parent aebe74f commit 10030f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 5 additions & 0 deletions t/lib/warnings/toke
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,11 @@ no warnings 'ambiguous';
EXPECT
Possible unintended interpolation of @mjd_previously_unused_ぁrrぁy in string at - line 5.
########
-w
# toke.c
$_ = "@DB::args";
EXPECT
########
# toke.c
# 20020328 mjd-perl-patch+@plover.com at behest of jfriedl@yahoo.com
use warnings 'regexp';
Expand Down
6 changes: 2 additions & 4 deletions toke.c
Original file line number Diff line number Diff line change
Expand Up @@ -8581,11 +8581,9 @@ S_pending_ident(pTHX)
&& !PL_lex_brackets)
{
GV *const gv = gv_fetchpvn_flags(PL_tokenbuf + 1, tokenbuf_len - 1,
( UTF ? SVf_UTF8 : 0 ), SVt_PVAV);
( UTF ? SVf_UTF8 : 0 ) | GV_ADDMG,
SVt_PVAV);
if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
/* DO NOT warn for @- and @+ */
&& !( PL_tokenbuf[2] == '\0'
&& ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
)
{
/* Downgraded from fatal to warning 20000522 mjd */
Expand Down

0 comments on commit 10030f4

Please sign in to comment.