diff options
author | Father Chrysostomos <sprout@cpan.org> | 2016-09-04 14:22:37 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2016-09-04 14:29:09 -0700 |
commit | bdc377e5e0c60dfb539423e956843489501ca2bd (patch) | |
tree | 83b6f39eee74b52500f4b6953010570938a29733 /t/comp | |
parent | ba0a4150f6f1604df236035adf6df18bd43de88e (diff) | |
download | perl-bdc377e5e0c60dfb539423e956843489501ca2bd.tar.gz |
[perl #129073] Assert failure: ${p{};sub p}()
When parsing the special ${var{subscript}} syntax, the lexer notes
that the } matching the ${ will be a fake bracket, and should
be ignored.
In the case of ${p{};sub p}() the first syntax error causes tokens to
be popped, such that the } following the sub declaration ends up being
the one treated as a fake bracket and ignored.
The part of the lexer that deals with sub declarations treats a ( fol-
lowing the sub name as a prototype (which is a single term) if signa-
tures are disabled, but ignores it and allows the rest of the lexer to
treat it as a parenthesis if signatures are enabled.
Hence, the part of the parser (perly.y) that parses signatures knows
that a parenthesis token can only come after a sub if signatures are
enabled, and asserts as much.
In the case of an error and tokens being discarded, a parenthesis may
come after a sub name as far as the parser is concerned, even though
there was a } in between that got discarded. The sub part of the
lexer, of course did not see the parenthesis because of the interven-
ing brace, and did not treat it as a prototype. So we get an asser-
tion failure.
The simplest fix is to loosen up the assertion and allow for anomalies
after errors. It does not hurt to go ahead and parse a signature at
this point, even though the feature is disabled, because there has
been a syntax error already, so the parsed code will never run, and
the parsed sub will not be installed.
Diffstat (limited to 't/comp')
-rw-r--r-- | t/comp/parser.t | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/t/comp/parser.t b/t/comp/parser.t index 981f2655da..2da145c090 100644 --- a/t/comp/parser.t +++ b/t/comp/parser.t @@ -543,6 +543,9 @@ eval "grep+grep"; # Used to crash [perl #125679] eval 'BEGIN {$^H=-1} \eval=time'; +# Used to fail an assertion [perl #129073] +eval '${p{};sub p}()'; + # RT #124207 syntax error during stringify can leave stringify op # with multiple children and assertion failures |