From: Gurusamy Sarathy Date: Sun, 23 Jan 2000 11:29:22 +0000 (+0000) Subject: fix diagnostics to report "our" vs "my" correctly X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=eb64745eccc492010733ac012342c6cacc81e103;p=p5sagit%2Fp5-mst-13.2.git fix diagnostics to report "our" vs "my" correctly p4raw-id: //depot/perl@4859 --- diff --git a/op.c b/op.c index 06b6a70..529506b 100644 --- a/op.c +++ b/op.c @@ -178,8 +178,8 @@ Perl_pad_allocmy(pTHX_ char *name) sv_setpv(sv, name); if (PL_in_my_stash) { if (*name != '$') - yyerror(Perl_form(aTHX_ "Can't declare class for non-scalar %s in \"my\"", - name)); + yyerror(Perl_form(aTHX_ "Can't declare class for non-scalar %s in \"%s\"", + name, PL_in_my == KEY_our ? "our" : "my")); SvOBJECT_on(sv); (void)SvUPGRADE(sv, SVt_PVMG); SvSTASH(sv) = (HV*)SvREFCNT_inc(PL_in_my_stash); @@ -1869,7 +1869,9 @@ S_my_kid(pTHX_ OP *o, OP *attrs) type != OP_PADHV && type != OP_PUSHMARK) { - yyerror(Perl_form(aTHX_ "Can't declare %s in my", PL_op_desc[o->op_type])); + yyerror(Perl_form(aTHX_ "Can't declare %s in \"%s\"", + PL_op_desc[o->op_type], + PL_in_my == KEY_our ? "our" : "my")); return o; } else if (attrs && type != OP_PUSHMARK) { @@ -1877,6 +1879,9 @@ S_my_kid(pTHX_ OP *o, OP *attrs) SV *padsv; SV **namesvp; + PL_in_my = FALSE; + PL_in_my_stash = Nullhv; + /* check for C when deciding package */ namesvp = av_fetch(PL_comppad_name, o->op_targ, FALSE); if (namesvp && *namesvp && SvOBJECT(*namesvp) && HvNAME(SvSTASH(*namesvp))) @@ -1896,11 +1901,12 @@ Perl_my_attrs(pTHX_ OP *o, OP *attrs) { if (o->op_flags & OPf_PARENS) list(o); - PL_in_my = FALSE; - PL_in_my_stash = Nullhv; if (attrs) SAVEFREEOP(attrs); - return my_kid(o, attrs); + o = my_kid(o, attrs); + PL_in_my = FALSE; + PL_in_my_stash = Nullhv; + return o; } OP * @@ -2111,16 +2117,18 @@ Perl_localize(pTHX_ OP *o, I32 lex) char *s; for (s = PL_bufptr; *s && (isALNUM(*s) || (*s & 0x80) || strchr("@$%, ",*s)); s++) ; if (*s == ';' || *s == '=') - Perl_warner(aTHX_ WARN_PARENTHESIS, "Parentheses missing around \"%s\" list", - lex ? "my" : "local"); + Perl_warner(aTHX_ WARN_PARENTHESIS, + "Parentheses missing around \"%s\" list", + lex ? (PL_in_my == KEY_our ? "our" : "my") : "local"); } } - PL_in_my = FALSE; - PL_in_my_stash = Nullhv; if (lex) - return my(o); + o = my(o); else - return mod(o, OP_NULL); /* a bit kludgey */ + o = mod(o, OP_NULL); /* a bit kludgey */ + PL_in_my = FALSE; + PL_in_my_stash = Nullhv; + return o; } OP * diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 98ae3ad..0da6cb3 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -42,9 +42,9 @@ yet. to try to declare one with a package qualifier on the front. Use local() if you want to localize a package variable. -=item "my" variable %s masks earlier declaration in same %s +=item "%s" variable %s masks earlier declaration in same %s -(W) A lexical variable has been redeclared in the current scope or statement, +(W) A "my" or "our" variable has been redeclared in the current scope or statement, effectively eliminating all access to the previous instance. This is almost always a typographical error. Note that the earlier variable will still exist until the end of the scope or until all closure referents to it are @@ -684,10 +684,16 @@ only with arrays that have a hash reference at index 0. (P) An error peculiar to VMS. The process is suffering from exhausted quotas or other plumbing problems. -=item Can't declare %s in my +=item Can't declare class for non-scalar %s in "%s" -(F) Only scalar, array, and hash variables may be declared as lexical variables. -They must have ordinary identifiers as names. +(S) Currently, only scalar variables can declared with a specific class +qualifier in a "my" or "our" declaration. The semantics may be extended +for other types of variables in future. + +=item Can't declare %s in "%s" + +(F) Only scalar, array, and hash variables may be declared as "my" or +"our" variables. They must have ordinary identifiers as names. =item Can't do inplace edit on %s: %s @@ -1514,8 +1520,9 @@ the line, and you really meant a "less than". =item Global symbol "%s" requires explicit package name (F) You've said "use strict vars", which indicates that all variables -must either be lexically scoped (using "my"), or explicitly qualified to -say which package the global variable is in (using "::"). +must either be lexically scoped (using "my"), declared beforehand using +"our", or explicitly qualified to say which package the global variable +is in (using "::"). =item goto must have label @@ -2395,7 +2402,7 @@ when you meant my ($foo, $bar) = @_; -Remember that "my" and "local" bind closer than comma. +Remember that "my", "our" and "local" bind closer than comma. =item Perl %3.3f required--this is only version %s, stopped