Skip to content

Commit 10030f4

Browse files
author
Father Chrysostomos
committed
Don’t trigger warnings for qq"@Builtin"
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.
1 parent aebe74f commit 10030f4

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

t/lib/warnings/toke

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,11 @@ no warnings 'ambiguous';
11121112
EXPECT
11131113
Possible unintended interpolation of @mjd_previously_unused_ぁrrぁy in string at - line 5.
11141114
########
1115+
-w
1116+
# toke.c
1117+
$_ = "@DB::args";
1118+
EXPECT
1119+
########
11151120
# toke.c
11161121
# 20020328 [email protected] at behest of [email protected]
11171122
use warnings 'regexp';

toke.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8581,11 +8581,9 @@ S_pending_ident(pTHX)
85818581
&& !PL_lex_brackets)
85828582
{
85838583
GV *const gv = gv_fetchpvn_flags(PL_tokenbuf + 1, tokenbuf_len - 1,
8584-
( UTF ? SVf_UTF8 : 0 ), SVt_PVAV);
8584+
( UTF ? SVf_UTF8 : 0 ) | GV_ADDMG,
8585+
SVt_PVAV);
85858586
if ((!gv || ((PL_tokenbuf[0] == '@') ? !GvAV(gv) : !GvHV(gv)))
8586-
/* DO NOT warn for @- and @+ */
8587-
&& !( PL_tokenbuf[2] == '\0'
8588-
&& ( PL_tokenbuf[1] == '-' || PL_tokenbuf[1] == '+' ))
85898587
)
85908588
{
85918589
/* Downgraded from fatal to warning 20000522 mjd */

0 commit comments

Comments
 (0)