In perl.git, the branch blead has been updated

<https://perl5.git.perl.org/perl.git/commitdiff/76b35304cf4800e9e0f7b370b9f1f40bc6cfb7e0?hp=304cc305d1f9c22eaa9ccfed1d472022f8bb82b8>

- Log -----------------------------------------------------------------
commit 76b35304cf4800e9e0f7b370b9f1f40bc6cfb7e0
Author: Father Chrysostomos <spr...@cpan.org>
Date:   Mon Dec 4 15:29:45 2017 -0800

    Make Bad name error less unhelpful
    
    This was brought up in perl #132485.
    
    Because ‘Bad name after...’ is a croak, it suppresses the more helpful
    hints like ‘Might be a runaway multi-line string’, in such cases as:
    
    use Moose;
    
    has erdef => (
        isa => 'Int',
        is => 'ro,
        default => sub { 1 }
    );
    
    has cxxc => (
        isa => 'Int',
        is => 'ro',
        default => sub { 1 }
    );
    
    We can allay this infelicity by emitting the ‘Missing operator before
    bareword’ before the Bad name croak, so in the example above we
    end up with:
    
    Bareword found where operator expected at - line 10, near "isa => 'Int"
      (Might be a runaway multi-line '' string starting on line 5)
        (Do you need to predeclare isa?)
    Bad name after Int' at - line 10.
    
    rather than just:
    
    Bad name after Int' at - line 10.

-----------------------------------------------------------------------

Summary of changes:
 t/lib/croak/toke | 38 ++++++++++++++++++++++++++++++++++++++
 toke.c           | 26 ++++++++++++++++++--------
 2 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/t/lib/croak/toke b/t/lib/croak/toke
index aadb447dc4..082761eec4 100644
--- a/t/lib/croak/toke
+++ b/t/lib/croak/toke
@@ -289,6 +289,44 @@ Too many arguments for undef operator at - line 11, near 
"2)"
 Constant(q) unknown at - line 12, near ""a""
 - has too many errors.
 ########
+# NAME Bad name after ' (with other helpful messages)
+sub has{}
+has erdef => (
+    isa => 'Int',
+    is => 'ro,
+    default => sub { 1 }
+);
+
+has cxxc => (
+    isa => 'Int',
+    is => 'ro',
+    default => sub { 1 }
+);
+EXPECT
+Bareword found where operator expected at - line 9, near "isa => 'Int"
+  (Might be a runaway multi-line '' string starting on line 4)
+       (Do you need to predeclare isa?)
+Bad name after Int' at - line 9.
+########
+# NAME Bad name after :: (with other helpful messages)
+sub has{}
+has erdef => (
+    isa => 'Int',
+    is => "ro,
+    default => sub { 1 }
+);
+
+has cxxc => (
+    isa => "Foo::$subpackage",
+    is => 'ro',
+    default => sub { 1 }
+);
+EXPECT
+Bareword found where operator expected at - line 9, near "isa => "Foo"
+  (Might be a runaway multi-line "" string starting on line 4)
+       (Do you need to predeclare isa?)
+Bad name after Foo:: at - line 9.
+########
 # NAME Unterminated delimiter for here document
 <<"foo
 EXPECT
diff --git a/toke.c b/toke.c
index 1074e7aed6..70e7de01de 100644
--- a/toke.c
+++ b/toke.c
@@ -7266,7 +7266,20 @@ Perl_yylex(pTHX)
                int pkgname = 0;
                const char lastchar = (PL_bufptr == PL_oldoldbufptr ? 0 : 
PL_bufptr[-1]);
                bool safebw;
+               bool no_op_error = FALSE;
 
+               if (PL_expect == XOPERATOR) {
+                   if (PL_bufptr == PL_linestart) {
+                       CopLINE_dec(PL_curcop);
+                       Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", 
PL_warn_nosemi);
+                       CopLINE_inc(PL_curcop);
+                   }
+                   else
+                       /* We want to call no_op with s pointing after the
+                          bareword, so defer it.  But we want it to come
+                          before the Bad name croak.  */
+                       no_op_error = TRUE;
+               }
 
                /* Get the rest if it looks like a package qualifier */
 
@@ -7274,6 +7287,10 @@ Perl_yylex(pTHX)
                    STRLEN morelen;
                    s = scan_word(s, PL_tokenbuf + len, sizeof PL_tokenbuf - 
len,
                                  TRUE, &morelen);
+                   if (no_op_error) {
+                       no_op("Bareword",s);
+                       no_op_error = FALSE;
+                   }
                    if (!morelen)
                        Perl_croak(aTHX_ "Bad name after %" UTF8f "%s",
                                UTF8fARG(UTF, len, PL_tokenbuf),
@@ -7282,15 +7299,8 @@ Perl_yylex(pTHX)
                    pkgname = 1;
                }
 
-               if (PL_expect == XOPERATOR) {
-                   if (PL_bufptr == PL_linestart) {
-                       CopLINE_dec(PL_curcop);
-                       Perl_warner(aTHX_ packWARN(WARN_SEMICOLON), "%s", 
PL_warn_nosemi);
-                       CopLINE_inc(PL_curcop);
-                   }
-                   else
+               if (no_op_error)
                        no_op("Bareword",s);
-               }
 
                /* See if the name is "Foo::",
                   in which case Foo is a bareword

-- 
Perl5 Master Repository

Reply via email to