summaryrefslogtreecommitdiff
path: root/perly.h
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2018-02-26 18:52:23 +0000
committerDavid Mitchell <davem@iabyn.com>2018-03-02 13:36:43 +0000
commita8c5635617479436b1775ba4ab34e4bc791eda54 (patch)
tree870dda66a262326c7e359e6c8fd7d45383b39867 /perly.h
parent86ae8d9a6f56e9e71efc1f3e556f6770dc07566e (diff)
downloadperl-a8c5635617479436b1775ba4ab34e4bc791eda54.tar.gz
detect sub attributes following a signature
RT #132760 A recent commit (v5.27.7-212-g894f226) moved subroutine attributes back before the subroutine's signature: e.g. sub foo :prototype($$) ($a, $b) { ... } # 5.18 and 5.28 + sub foo ($a, $b) :prototype($$) { ... } # 5.20 .. 5.26 This change means that any code still using an attribute following the signature is going to trigger a syntax error. However, the error, followed by error recovery and further warnings and errors, is very unfriendly and gives no indication of the root cause. This commit introduces a new error, "Subroutine attributes must come before the signature". For example, List::Lazy, the subject of the ticket, failed to compile tests, with output like: Array found where operator expected at blib/lib/List/Lazy.pm line 43, near "$$@)" (Missing operator before @)?) "my" variable $step masks earlier declaration in same statement at blib/lib/List/Lazy.pm line 44. syntax error at blib/lib/List/Lazy.pm line 36, near ") :" Global symbol "$generator" requires explicit package name (did you forget to declare "my $generator"?) at blib/lib/List/Lazy.pm line 38. Global symbol "$state" requires explicit package name (did you forget to declare "my $state"?) at blib/lib/List/Lazy.pm line 39. Global symbol "$min" requires explicit package name (did you forget to declare "my $min"?) at blib/lib/List/Lazy.pm line 43. Global symbol "$max" requires explicit package name (did you forget to declare "my $max"?) at blib/lib/List/Lazy.pm line 43. Global symbol "$step" requires explicit package name (did you forget to declare "my $step"?) at blib/lib/List/Lazy.pm line 43. Invalid separator character '{' in attribute list at blib/lib/List/Lazy.pm line 44, near "$step : sub " Global symbol "$step" requires explicit package name (did you forget to declare "my $step"?) at blib/lib/List/Lazy.pm line 44. But following this commit, it now just outputs: Subroutine attributes must come before the signature at blib/lib/List/Lazy.pm line 36. Compilation failed in require at t/append.t line 5. BEGIN failed--compilation aborted at t/append.t line 5. It works by: 1) adding a boolean flag (sig_seen) to the parser state to indicate that a signature has been parsed; 2) at the end of parsing a signature, PL_expect is set to XATTRBLOCK rather than XBLOCK. Then if something looking like one or more attributes is encountered by the lexer immediately afterwards, it scans it as if it were an attribute, but then if sig_seen is true, it croaks.
Diffstat (limited to 'perly.h')
-rw-r--r--perly.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/perly.h b/perly.h
index 66771226e1..7727e7bf1b 100644
--- a/perly.h
+++ b/perly.h
@@ -183,6 +183,6 @@ int yyparse (void);
/* Generated from:
- * 1464f62136e1c8980247e644a1b280abdab234c9615dcbc70e089ab38123122b perly.y
+ * ac323bb6f3cacf4eb8eda6403a58c41f30954d07a4a6d6f7f00de81577b2c79a perly.y
* b6fae5748f9bef6db4740aa5e122b84ac5181852d42474d0ecad621fa4253306 regen_perly.pl
* ex: set ro: */