From: Chip Salzenberg Date: Sat, 4 Jul 1998 20:51:36 +0000 (-0400) Subject: added patch with tweak to doc X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=56f7f34be21c292a158b632263ab6132603bb8ec;p=p5sagit%2Fp5-mst-13.2.git added patch with tweak to doc Message-ID: <19980704205136.A16319@perlsupport.com> Subject: [PATCH _69] Take 2: Warn on C p4raw-id: //depot/perl@1317 --- diff --git a/ext/IO/lib/IO/Handle.pm b/ext/IO/lib/IO/Handle.pm index 39e32f0..d3b0ce4 100644 --- a/ext/IO/lib/IO/Handle.pm +++ b/ext/IO/lib/IO/Handle.pm @@ -207,7 +207,7 @@ use SelectSaver; require Exporter; @ISA = qw(Exporter); -$VERSION = "1.1504"; +$VERSION = "1.1505"; $XS_VERSION = "1.15"; @EXPORT_OK = qw( @@ -520,10 +520,10 @@ sub format_write { if (@_ == 2) { my ($fh, $fmt) = @_; my $oldfmt = $fh->format_name($fmt); - write($fh); + CORE::write($fh); $fh->format_name($oldfmt); } else { - write($_[0]); + CORE::write($_[0]); } } diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 3851bac..7c8ab3d 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -1759,7 +1759,7 @@ will extend the buffer and zero pad the new area. (S) An internal warning that the grammar is screwed up. -=item Operation `%s': no method found,%s +=item Operation `%s': no method found, %s (F) An attempt was made to perform an overloaded operation for which no handler was defined. While some handlers can be autogenerated in @@ -2358,6 +2358,21 @@ may break this. eval "sub name { ... }"; } +=item Subroutine %s hidden by keyword; use ampersand + +(W) You are trying to call a subroutine that has the same name as a +keyword. However, because the subroutine is not imported and +you're not using an ampersand, Perl won't call the subroutine. + +To force a subroutine call, either put an ampersand before the +subroutine name, or qualify the name with its package. Alternatively, +you can import the subroutine (or pretend that it's imported with the +C pragma). + +If the Perl operator is what you want, then eliminate this warning by +using the CORE:: prefix on the operator (e.g. CORE::log($x)) or by +declaring the subroutine to be an object method (see L). + =item Substitution loop (P) The substitution was looping infinitely. (Obviously, a diff --git a/toke.c b/toke.c index 65480b4..7020572 100644 --- a/toke.c +++ b/toke.c @@ -2821,14 +2821,28 @@ yylex(void) } if (tmp < 0) { /* second-class keyword? */ - if (expect != XOPERATOR && (*s != ':' || s[1] != ':') && - (((gv = gv_fetchpv(tokenbuf, FALSE, SVt_PVCV)) && - GvCVu(gv) && GvIMPORTED_CV(gv)) || - ((gvp = (GV**)hv_fetch(globalstash,tokenbuf,len,FALSE)) && - (gv = *gvp) != (GV*)&sv_undef && - GvCVu(gv) && GvIMPORTED_CV(gv)))) - { - tmp = 0; /* overridden by importation */ + GV *ogv = Nullgv; /* override (winner) */ + GV *hgv = Nullgv; /* hidden (loser) */ + if (expect != XOPERATOR && (*s != ':' || s[1] != ':')) { + CV *cv; + if ((gv = gv_fetchpv(tokenbuf, FALSE, SVt_PVCV)) && + (cv = GvCVu(gv))) + { + if (GvIMPORTED_CV(gv)) + ogv = gv; + else if (! CvMETHOD(cv)) + hgv = gv; + } + if (!ogv && + (gvp = (GV**)hv_fetch(globalstash,tokenbuf,len,FALSE)) && + (gv = *gvp) != (GV*)&sv_undef && + GvCVu(gv) && GvIMPORTED_CV(gv)) + { + ogv = gv; + } + } + if (ogv) { + tmp = 0; /* overridden by import or by GLOBAL */ } else if (gv && !gvp && -tmp==KEY_lock /* XXX generalizable kludge */ @@ -2836,8 +2850,13 @@ yylex(void) { tmp = 0; /* any sub overrides "weak" keyword */ } - else { - tmp = -tmp; gv = Nullgv; gvp = 0; + else { /* no override */ + tmp = -tmp; + gv = Nullgv; + gvp = 0; + if (dowarn && hgv) + warn("Subroutine %s::%s hidden by keyword; use ampersand", + HvNAME(GvESTASH(hgv)), GvENAME(hgv)); } }