summaryrefslogtreecommitdiff
path: root/toke.c
diff options
context:
space:
mode:
authorRenee Baecker <renee.baecker@smart-websolutions.de>2008-05-26 15:08:27 +0200
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2008-06-08 08:57:00 +0000
commit9e8d7757ba54bcb0e5a4571f5fbc9ca113df7b70 (patch)
tree8aa1e7627266014fa11374457c5e47303e9416da /toke.c
parent26ab4e07be0b42218adc42b9cf6c2f4b2adf2d2f (diff)
downloadperl-9e8d7757ba54bcb0e5a4571f5fbc9ca113df7b70.tar.gz
Add a new warning, "Prototype after '%s'"
Based on: Subject: Re: [perl #36673] sub foo(@$) {} should generate an error Message-ID: <483A9A2B.6020808@smart-websolutions.de> p4raw-id: //depot/perl@34021
Diffstat (limited to 'toke.c')
-rw-r--r--toke.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/toke.c b/toke.c
index b76e4340b0..5f75233b60 100644
--- a/toke.c
+++ b/toke.c
@@ -6744,6 +6744,11 @@ Perl_yylex(pTHX)
if (*s == '(') {
char *p;
bool bad_proto = FALSE;
+ bool in_brackets = FALSE;
+ char greedy_proto = ' ';
+ bool proto_after_greedy_proto = FALSE;
+ bool must_be_last = FALSE;
+ bool underscore = FALSE;
const bool warnsyntax = ckWARN(WARN_SYNTAX);
s = scan_str(s,!!PL_madskills,FALSE);
@@ -6755,11 +6760,43 @@ Perl_yylex(pTHX)
for (p = d; *p; ++p) {
if (!isSPACE(*p)) {
d[tmp++] = *p;
- if (warnsyntax && !strchr("$@%*;[]&\\_", *p))
- bad_proto = TRUE;
+
+ if (warnsyntax) {
+ if (must_be_last)
+ proto_after_greedy_proto = TRUE;
+ if (!strchr("$@%*;[]&\\_", *p)) {
+ bad_proto = TRUE;
+ }
+ else {
+ if ( underscore ) {
+ if ( *p != ';' )
+ bad_proto = TRUE;
+ underscore = FALSE;
+ }
+ if ( *p == '[' ) {
+ in_brackets = TRUE;
+ }
+ else if ( *p == ']' ) {
+ in_brackets = FALSE;
+ }
+ else if ( (*p == '@' || *p == '%') &&
+ ( tmp < 2 || d[tmp-2] != '\\' ) &&
+ !in_brackets ) {
+ must_be_last = TRUE;
+ greedy_proto = *p;
+ }
+ else if ( *p == '_' ) {
+ underscore = TRUE;
+ }
+ }
+ }
}
}
d[tmp] = '\0';
+ if (proto_after_greedy_proto)
+ Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
+ "Prototype after '%c' for %"SVf" : %s",
+ greedy_proto, SVfARG(PL_subname), d);
if (bad_proto)
Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
"Illegal character in prototype for %"SVf" : %s",