This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don’t warn for foo+1 with ($) proto
authorFather Chrysostomos <sprout@cpan.org>
Fri, 25 Nov 2011 03:20:00 +0000 (19:20 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 25 Nov 2011 05:11:05 +0000 (21:11 -0800)
Commit 22393538 added the warning for (;$) prototypes, but
ended up adding it for ($) as well.

t/lib/warnings/toke
toke.c

index cb1dbca..95612eb 100644 (file)
@@ -609,9 +609,11 @@ Warning: Use of "rand" without parentheses is ambiguous at - line 10.
 ########
 # [perl #97110]
 sub myrand(;$) { }
+sub whatever($) { }
 my $a = myrand + 4 ;
+my $b = whatever + 4 ;
 EXPECT
-Warning: Use of "myrand" without parentheses is ambiguous at - line 3.
+Warning: Use of "myrand" without parentheses is ambiguous at - line 4.
 ########
 # toke.c
 use warnings "ambiguous";
diff --git a/toke.c b/toke.c
index c9206a5..a9b5e49 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -285,8 +285,8 @@ static const char* const lex_state_names[] = {
        }
 #define UNI(f)    UNI2(f,XTERM)
 #define UNIDOR(f) UNI2(f,XTERMORDORDOR)
-#define UNIPROTO(f) { \
-       PL_last_uni = PL_oldbufptr; \
+#define UNIPROTO(f,optional) { \
+       if (optional) PL_last_uni = PL_oldbufptr; \
        OPERATOR(f); \
        }
 
@@ -6851,10 +6851,13 @@ Perl_yylex(pTHX)
                    {
                        STRLEN protolen = CvPROTOLEN(cv);
                        const char *proto = CvPROTO(cv);
+                       bool optional;
                        if (!protolen)
                            TERM(FUNC0SUB);
-                       while (*proto == ';')
+                       if ((optional = *proto == ';'))
+                         do
                            proto++;
+                         while (*proto == ';');
                        if (
                            (
                                (
@@ -6867,12 +6870,13 @@ Perl_yylex(pTHX)
                             *proto == '\\' && proto[1] && proto[2] == '\0'
                            )
                        )
-                           UNIPROTO(UNIOPSUB);
+                           UNIPROTO(UNIOPSUB,optional);
                        if (*proto == '\\' && proto[1] == '[') {
                            const char *p = proto + 2;
                            while(*p && *p != ']')
                                ++p;
-                           if(*p == ']' && !p[1]) UNIPROTO(UNIOPSUB);
+                           if(*p == ']' && !p[1])
+                               UNIPROTO(UNIOPSUB,optional);
                        }
                        if (*proto == '&' && *s == '{') {
                            if (PL_curstash)