diff options
author | Father Chrysostomos <sprout@cpan.org> | 2014-09-18 20:34:43 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2014-09-18 21:30:48 -0700 |
commit | d8c6310a4f016fa2e6af68b606ee53084fbf4a8a (patch) | |
tree | 87ae75029c6185644f02939acacc1e28f63f3d90 | |
parent | 99f74b09f61407826aeb0bf8eabad6e2e628c02b (diff) | |
download | perl-d8c6310a4f016fa2e6af68b606ee53084fbf4a8a.tar.gz |
[perl #121638] Make ‘Global symbol’ message more newbie-friendly
by suggesting the declaration of a lexical variable, but without
removing the ‘Global symbol’ part, since much code no doubt depends
on its presence.
-rw-r--r-- | ext/B/t/optree_concise.t | 6 | ||||
-rw-r--r-- | gv.c | 7 | ||||
-rw-r--r-- | t/lib/strict/subs | 4 | ||||
-rw-r--r-- | t/lib/strict/vars | 82 | ||||
-rw-r--r-- | t/run/runenv.t | 4 | ||||
-rw-r--r-- | t/run/switchM.t | 6 | ||||
-rw-r--r-- | t/win32/runenv.t | 4 |
7 files changed, 61 insertions, 52 deletions
diff --git a/ext/B/t/optree_concise.t b/ext/B/t/optree_concise.t index aa28ebb14c..f9a272926d 100644 --- a/ext/B/t/optree_concise.t +++ b/ext/B/t/optree_concise.t @@ -264,7 +264,7 @@ checkOptree ( name => 'cmdline self-strict compile err using prog', prog => 'use strict; sort @a', bcopts => [qw/ -basic -concise -exec /], - errs => 'Global symbol "@a" requires explicit package name at -e line 1.', + errs => 'Global symbol "@a" requires explicit package name (did you forget to declare "my @a"?) at -e line 1.', expect => 'nextstate', expect_nt => 'nextstate', noanchors => 1, # allow simple expectations to work @@ -274,7 +274,9 @@ checkOptree ( name => 'cmdline self-strict compile err using code', code => 'use strict; sort @a', bcopts => [qw/ -basic -concise -exec /], - errs => qr/Global symbol "\@a" requires explicit package name at .*? line 1\./, + errs => qr/Global symbol "\@a" requires explicit package (?x: + )name \(did you forget to declare "my \@a"\?\) at (?x: + ).*? line 1\./, note => 'this test relys on a kludge which copies $@ to rendering when empty', expect => 'Global symbol', expect_nt => 'Global symbol', @@ -1733,7 +1733,12 @@ S_find_default_stash(pTHX_ HV **stash, const char *name, STRLEN len, if (add && !PL_in_clean_all) { SV * const err = Perl_mess(aTHX_ "Global symbol \"%s%"UTF8f - "\" requires explicit package name", + "\" requires explicit package name (did you forget to " + "declare \"my %s%"UTF8f"\"?)", + (sv_type == SVt_PV ? "$" + : sv_type == SVt_PVAV ? "@" + : sv_type == SVt_PVHV ? "%" + : ""), UTF8fARG(is_utf8, len, name), (sv_type == SVt_PV ? "$" : sv_type == SVt_PVAV ? "@" : sv_type == SVt_PVHV ? "%" diff --git a/t/lib/strict/subs b/t/lib/strict/subs index 5fd0b03de7..095adee4cf 100644 --- a/t/lib/strict/subs +++ b/t/lib/strict/subs @@ -108,7 +108,7 @@ use strict 'vars' ; $joe = 1 ; EXPECT Variable "$joe" is not imported at - line 8. -Global symbol "$joe" requires explicit package name at - line 8. +Global symbol "$joe" requires explicit package name (did you forget to declare "my $joe"?) at - line 8. Execution of - aborted due to compilation errors. ######## @@ -120,7 +120,7 @@ no strict; } $joe = 1 ; EXPECT -Global symbol "$joe" requires explicit package name at - line 6. +Global symbol "$joe" requires explicit package name (did you forget to declare "my $joe"?) at - line 6. Execution of - aborted due to compilation errors. ######## diff --git a/t/lib/strict/vars b/t/lib/strict/vars index c6cb067939..b571751b52 100644 --- a/t/lib/strict/vars +++ b/t/lib/strict/vars @@ -49,7 +49,7 @@ EXPECT use strict ; $fred ; EXPECT -Global symbol "$fred" requires explicit package name at - line 4. +Global symbol "$fred" requires explicit package name (did you forget to declare "my $fred"?) at - line 4. Execution of - aborted due to compilation errors. ######## @@ -57,7 +57,7 @@ Execution of - aborted due to compilation errors. use strict 'vars' ; <$fred> ; EXPECT -Global symbol "$fred" requires explicit package name at - line 4. +Global symbol "$fred" requires explicit package name (did you forget to declare "my $fred"?) at - line 4. Execution of - aborted due to compilation errors. ######## @@ -65,7 +65,7 @@ Execution of - aborted due to compilation errors. use strict 'vars' ; local $fred ; EXPECT -Global symbol "$fred" requires explicit package name at - line 4. +Global symbol "$fred" requires explicit package name (did you forget to declare "my $fred"?) at - line 4. Execution of - aborted due to compilation errors. ######## @@ -78,7 +78,7 @@ use strict 'vars' ; $joe = 1 ; EXPECT Variable "$joe" is not imported at - line 8. -Global symbol "$joe" requires explicit package name at - line 8. +Global symbol "$joe" requires explicit package name (did you forget to declare "my $joe"?) at - line 8. Execution of - aborted due to compilation errors. ######## @@ -93,7 +93,7 @@ use open qw( :utf8 :std ); $jòè = 1 ; EXPECT Variable "$jòè" is not imported at - line 10. -Global symbol "$jòè" requires explicit package name at - line 10. +Global symbol "$jòè" requires explicit package name (did you forget to declare "my $jòè"?) at - line 10. Execution of - aborted due to compilation errors. ######## @@ -105,7 +105,7 @@ no strict; } $joe = 1 ; EXPECT -Global symbol "$joe" requires explicit package name at - line 6. +Global symbol "$joe" requires explicit package name (did you forget to declare "my $joe"?) at - line 6. Execution of - aborted due to compilation errors. ######## @@ -138,7 +138,7 @@ $joe = 1 ; require "./abc"; EXPECT Variable "$joe" is not imported at ./abc line 2. -Global symbol "$joe" requires explicit package name at ./abc line 2. +Global symbol "$joe" requires explicit package name (did you forget to declare "my $joe"?) at ./abc line 2. Compilation failed in require at - line 2. ######## @@ -155,7 +155,7 @@ $jòè = 1 ; require "./abc"; EXPECT Variable "$jòè" is not imported at ./abc line 4. -Global symbol "$jòè" requires explicit package name at ./abc line 4. +Global symbol "$jòè" requires explicit package name (did you forget to declare "my $jòè"?) at ./abc line 4. Compilation failed in require at - line 4. ######## @@ -168,7 +168,7 @@ $joe = 1 ; use abc; EXPECT Variable "$joe" is not imported at abc.pm line 2. -Global symbol "$joe" requires explicit package name at abc.pm line 2. +Global symbol "$joe" requires explicit package name (did you forget to declare "my $joe"?) at abc.pm line 2. Compilation failed in require at - line 2. BEGIN failed--compilation aborted at - line 2. ######## @@ -186,7 +186,7 @@ $jòè = 1 ; use abc; EXPECT Variable "$jòè" is not imported at abc.pm line 4. -Global symbol "$jòè" requires explicit package name at abc.pm line 4. +Global symbol "$jòè" requires explicit package name (did you forget to declare "my $jòè"?) at abc.pm line 4. Compilation failed in require at - line 4. BEGIN failed--compilation aborted at - line 4. ######## @@ -203,20 +203,20 @@ $p = 0b12; --FILE-- use abc; EXPECT -Global symbol "$f" requires explicit package name at abc.pm line 3. -Global symbol "$k" requires explicit package name at abc.pm line 3. -Global symbol "$g" requires explicit package name at abc.pm line 4. -Global symbol "$l" requires explicit package name at abc.pm line 4. -Global symbol "$c" requires explicit package name at abc.pm line 5. -Global symbol "$h" requires explicit package name at abc.pm line 5. -Global symbol "$m" requires explicit package name at abc.pm line 5. -Global symbol "$d" requires explicit package name at abc.pm line 6. -Global symbol "$i" requires explicit package name at abc.pm line 6. -Global symbol "$n" requires explicit package name at abc.pm line 6. -Global symbol "$e" requires explicit package name at abc.pm line 7. -Global symbol "$j" requires explicit package name at abc.pm line 7. -Global symbol "$o" requires explicit package name at abc.pm line 7. -Global symbol "$p" requires explicit package name at abc.pm line 8. +Global symbol "$f" requires explicit package name (did you forget to declare "my $f"?) at abc.pm line 3. +Global symbol "$k" requires explicit package name (did you forget to declare "my $k"?) at abc.pm line 3. +Global symbol "$g" requires explicit package name (did you forget to declare "my $g"?) at abc.pm line 4. +Global symbol "$l" requires explicit package name (did you forget to declare "my $l"?) at abc.pm line 4. +Global symbol "$c" requires explicit package name (did you forget to declare "my $c"?) at abc.pm line 5. +Global symbol "$h" requires explicit package name (did you forget to declare "my $h"?) at abc.pm line 5. +Global symbol "$m" requires explicit package name (did you forget to declare "my $m"?) at abc.pm line 5. +Global symbol "$d" requires explicit package name (did you forget to declare "my $d"?) at abc.pm line 6. +Global symbol "$i" requires explicit package name (did you forget to declare "my $i"?) at abc.pm line 6. +Global symbol "$n" requires explicit package name (did you forget to declare "my $n"?) at abc.pm line 6. +Global symbol "$e" requires explicit package name (did you forget to declare "my $e"?) at abc.pm line 7. +Global symbol "$j" requires explicit package name (did you forget to declare "my $j"?) at abc.pm line 7. +Global symbol "$o" requires explicit package name (did you forget to declare "my $o"?) at abc.pm line 7. +Global symbol "$p" requires explicit package name (did you forget to declare "my $p"?) at abc.pm line 8. Illegal binary digit '2' at abc.pm line 8, at end of line abc.pm has too many errors. Compilation failed in require at - line 1. @@ -243,7 +243,7 @@ eval { print STDERR $@; $joe = 1 ; EXPECT -Global symbol "$joe" requires explicit package name at - line 6. +Global symbol "$joe" requires explicit package name (did you forget to declare "my $joe"?) at - line 6. Execution of - aborted due to compilation errors. ######## @@ -255,8 +255,8 @@ eval { print STDERR $@; $joe = 1 ; EXPECT -Global symbol "$joe" requires explicit package name at - line 5. -Global symbol "$joe" requires explicit package name at - line 8. +Global symbol "$joe" requires explicit package name (did you forget to declare "my $joe"?) at - line 5. +Global symbol "$joe" requires explicit package name (did you forget to declare "my $joe"?) at - line 8. Execution of - aborted due to compilation errors. ######## @@ -270,7 +270,7 @@ print STDERR $@; $joe = 1 ; EXPECT Variable "$joe" is not imported at - line 9. -Global symbol "$joe" requires explicit package name at - line 9. +Global symbol "$joe" requires explicit package name (did you forget to declare "my $joe"?) at - line 9. Execution of - aborted due to compilation errors. ######## @@ -286,7 +286,7 @@ print STDERR $@; $jòè = 1 ; EXPECT Variable "$jòè" is not imported at - line 11. -Global symbol "$jòè" requires explicit package name at - line 11. +Global symbol "$jòè" requires explicit package name (did you forget to declare "my $jòè"?) at - line 11. Execution of - aborted due to compilation errors. ######## @@ -307,7 +307,7 @@ eval q[ $joe = 1 ; ]; print STDERR $@; EXPECT -Global symbol "$joe" requires explicit package name at (eval 1) line 3. +Global symbol "$joe" requires explicit package name (did you forget to declare "my $joe"?) at (eval 1) line 3. ######## # Check scope of pragma with eval @@ -316,7 +316,7 @@ eval ' $joe = 1 ; '; print STDERR $@ ; EXPECT -Global symbol "$joe" requires explicit package name at (eval 1) line 2. +Global symbol "$joe" requires explicit package name (did you forget to declare "my $joe"?) at (eval 1) line 2. ######## # Check scope of pragma with eval @@ -327,7 +327,7 @@ eval ' '; print STDERR $@; $joe = 1 ; EXPECT -Global symbol "$joe" requires explicit package name at - line 8. +Global symbol "$joe" requires explicit package name (did you forget to declare "my $joe"?) at - line 8. Execution of - aborted due to compilation errors. ######## @@ -340,9 +340,9 @@ $ret = eval q{ print $x; }; print $@; print "ok 2\n" unless defined $ret; EXPECT -Global symbol "$x" requires explicit package name at (eval 1) line 1. +Global symbol "$x" requires explicit package name (did you forget to declare "my $x"?) at (eval 1) line 1. ok 1 -Global symbol "$x" requires explicit package name at (eval 2) line 1. +Global symbol "$x" requires explicit package name (did you forget to declare "my $x"?) at (eval 2) line 1. ok 2 ######## @@ -399,7 +399,7 @@ sub foo { $fred ; EXPECT Variable "$fred" is not imported at - line 8. -Global symbol "$fred" requires explicit package name at - line 8. +Global symbol "$fred" requires explicit package name (did you forget to declare "my $fred"?) at - line 8. Execution of - aborted due to compilation errors. ######## @@ -414,7 +414,7 @@ sub fòò { $frèd ; EXPECT Variable "$frèd" is not imported at - line 10. -Global symbol "$frèd" requires explicit package name at - line 10. +Global symbol "$frèd" requires explicit package name (did you forget to declare "my $frèd"?) at - line 10. Execution of - aborted due to compilation errors. ######## @@ -502,7 +502,7 @@ use strict 'vars'; no warnings; "@i_like_crackers"; EXPECT -Global symbol "@i_like_crackers" requires explicit package name at - line 7. +Global symbol "@i_like_crackers" requires explicit package name (did you forget to declare "my @i_like_crackers"?) at - line 7. Execution of - aborted due to compilation errors. ######## @@ -510,15 +510,15 @@ Execution of - aborted due to compilation errors. use strict 'vars'; @k = <$k>; EXPECT -Global symbol "@k" requires explicit package name at - line 4. -Global symbol "$k" requires explicit package name at - line 4. +Global symbol "@k" requires explicit package name (did you forget to declare "my @k"?) at - line 4. +Global symbol "$k" requires explicit package name (did you forget to declare "my $k"?) at - line 4. Execution of - aborted due to compilation errors. ######## # [perl #26910] hints not propagated into (?{...}) use strict 'vars'; qr/(?{$foo++})/; EXPECT -Global symbol "$foo" requires explicit package name at - line 3. +Global symbol "$foo" requires explicit package name (did you forget to declare "my $foo"?) at - line 3. Execution of - aborted due to compilation errors. ######## # Regex compilation errors weren't UTF-8 clean. @@ -527,7 +527,7 @@ use utf8; use open qw( :utf8 :std ); qr/(?{$fòò++})/; EXPECT -Global symbol "$fòò" requires explicit package name at - line 5. +Global symbol "$fòò" requires explicit package name (did you forget to declare "my $fòò"?) at - line 5. Execution of - aborted due to compilation errors. ######## # [perl #73712] 'Variable is not imported' should be suppressible diff --git a/t/run/runenv.t b/t/run/runenv.t index 9380d2400a..82846a4d28 100644 --- a/t/run/runenv.t +++ b/t/run/runenv.t @@ -99,12 +99,12 @@ try({PERL5OPT => '-Mstrict'}, ['-I../lib', '-e', 'print $::x'], try({PERL5OPT => '-Mstrict'}, ['-I../lib', '-e', 'print $x'], "", - qq{Global symbol "\$x" requires explicit package name at -e line 1.\nExecution of -e aborted due to compilation errors.\n}); + qq{Global symbol "\$x" requires explicit package name (did you forget to declare "my \$x"?) at -e line 1.\nExecution of -e aborted due to compilation errors.\n}); # Fails in 5.6.0 try({PERL5OPT => '-Mstrict -w'}, ['-I../lib', '-e', 'print $x'], "", - qq{Global symbol "\$x" requires explicit package name at -e line 1.\nExecution of -e aborted due to compilation errors.\n}); + qq{Global symbol "\$x" requires explicit package name (did you forget to declare "my \$x"?) at -e line 1.\nExecution of -e aborted due to compilation errors.\n}); # Fails in 5.6.0 try({PERL5OPT => '-w -Mstrict'}, ['-I../lib', '-e', 'print $::x'], diff --git a/t/run/switchM.t b/t/run/switchM.t index d2b5994a71..603d5c5fa0 100644 --- a/t/run/switchM.t +++ b/t/run/switchM.t @@ -14,11 +14,13 @@ require './test.pl'; plan(4); like(runperl(switches => ['-Irun/flib', '-Mbroken'], stderr => 1), - qr/^Global symbol "\$x" requires explicit package name at run\/flib\/broken.pm line 6\./, + qr/^Global symbol "\$x" requires explicit package name \(did you (?x: + )forget to declare "my \$x"\?\) at run\/flib\/broken.pm line 6\./, "Ensure -Irun/flib produces correct filename in warnings"); like(runperl(switches => ['-Irun/flib/', '-Mbroken'], stderr => 1), - qr/^Global symbol "\$x" requires explicit package name at run\/flib\/broken.pm line 6\./, + qr/^Global symbol "\$x" requires explicit package name \(did you (?x: + )forget to declare "my \$x"\?\) at run\/flib\/broken.pm line 6\./, "Ensure -Irun/flib/ produces correct filename in warnings"); SKIP: { diff --git a/t/win32/runenv.t b/t/win32/runenv.t index d487ea7344..0e2b0ca015 100644 --- a/t/win32/runenv.t +++ b/t/win32/runenv.t @@ -96,12 +96,12 @@ try({PERL5OPT => '-Mstrict'}, ['-I..\lib', '-e', '"print $::x"'], try({PERL5OPT => '-Mstrict'}, ['-I..\lib', '-e', '"print $x"'], "", - qq(Global symbol "\$x" requires explicit package name at -e line 1.${NL}Execution of -e aborted due to compilation errors.${NL})); + qq(Global symbol "\$x" requires explicit package name (did you forget to declare "my \$x"?) at -e line 1.${NL}Execution of -e aborted due to compilation errors.${NL})); # Fails in 5.6.0 try({PERL5OPT => '-Mstrict -w'}, ['-I..\lib', '-e', '"print $x"'], "", - qq(Global symbol "\$x" requires explicit package name at -e line 1.${NL}Execution of -e aborted due to compilation errors.${NL})); + qq(Global symbol "\$x" requires explicit package name (did you forget to declare "my \$x"?) at -e line 1.${NL}Execution of -e aborted due to compilation errors.${NL})); # Fails in 5.6.0 try({PERL5OPT => '-w -Mstrict'}, ['-I..\lib', '-e', '"print $::x"'], |