summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>2000-01-23 11:29:22 +0000
committerGurusamy Sarathy <gsar@cpan.org>2000-01-23 11:29:22 +0000
commiteb64745eccc492010733ac012342c6cacc81e103 (patch)
tree0b84661aed44e78b2584e3c40abbe57e7493c36d
parentea3df0f8158553b30d62cefd0eb7dd1b01ea72f2 (diff)
downloadperl-eb64745eccc492010733ac012342c6cacc81e103.tar.gz
fix diagnostics to report "our" vs "my" correctly
p4raw-id: //depot/perl@4859
-rw-r--r--op.c32
-rw-r--r--pod/perldiag.pod23
2 files changed, 35 insertions, 20 deletions
diff --git a/op.c b/op.c
index 06b6a7066a..529506b90e 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<my Dog $spot> 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 98ae3ad1d1..0da6cb3db3 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