diff options
author | Hio <hio@hio.jp> | 2013-10-18 16:48:47 +0100 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2013-10-18 16:48:47 +0100 |
commit | 61bc22580524a6d92bf31b2046baa6dcc4e400d4 (patch) | |
tree | 62d904f3e94ecdeeac656893181694bd8131d0fb | |
parent | 90eaaf02689a95627535076b787e35a0332ab2d5 (diff) | |
download | perl-61bc22580524a6d92bf31b2046baa6dcc4e400d4.tar.gz |
Correctly parse class name in 'for my class $foo
The code in toke.c on encountering 'for my' or for our',
skips past any optional package name, then checks that the next thing is a
'$', so that it can give a "Missing $ on loop variable" error if
necessary.
However, the code to skip the package name was using scan_ident() rather
than scan_word(); the latter assumes that the first char was the sigil,
and starts scanning from the second char onwards. So in something like
for my a1b $x (...)
scan_ident() starts scanning at '1b' in 'a1b', thinks it scanning $1 or
similar, and stops at the first non-digit char, in this case the b.
The fix is to use parse_word() instead.
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | t/comp/parser.t | 12 | ||||
-rw-r--r-- | toke.c | 2 |
3 files changed, 10 insertions, 5 deletions
@@ -460,6 +460,7 @@ Henrik Tougaard <ht.000@foa.dk> Herbert Breunung <lichtkind@cpan.org> Hernan Perez Masci <hmasci@uolsinectis.com.ar> Hershel Walters <walters@smd4d.wes.army.mil> +Hio <hio@hio.jp> Hojung Youn <amoc.yn@gmail.com> Holger Bechtold Hongwen Qiu <qiuhongwen@gmail.com> diff --git a/t/comp/parser.t b/t/comp/parser.t index 8fd7e85957..7caa116c7d 100644 --- a/t/comp/parser.t +++ b/t/comp/parser.t @@ -8,7 +8,7 @@ BEGIN { chdir 't'; } -print "1..168\n"; +print "1..169\n"; sub failed { my ($got, $expected, $name) = @_; @@ -333,10 +333,10 @@ like($@, qr/BEGIN failed--compilation aborted/, 'BEGIN 7' ); eval qq[ *$xFD ]; like($@, qr/Identifier too long/, "too long id in glob ctx"); - eval qq[ for $xFD ]; + eval qq[ for $xFC ]; like($@, qr/Missing \$ on loop variable/, - "253 char id ok, but a different error"); - eval qq[ for $xFE; ]; + "252 char id ok, but a different error"); + eval qq[ for $xFD; ]; like($@, qr/Identifier too long/, "too long id in for ctx"); # the specific case from the ticket @@ -495,6 +495,10 @@ eval 'Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo' .'ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo'; like $@, "^Identifier too long at ", 'ident buffer overflow'; +eval 'for my a1b $i (1) {}'; +# ng: 'Missing $ on loop variable' +like $@, "^No such class a1b at ", 'TYPE of my of for statement'; + # Add new tests HERE (above this line) # bug #74022: Loop on characters in \p{OtherIDContinue} @@ -8035,7 +8035,7 @@ Perl_yylex(pTHX) p += 3; p = PEEKSPACE(p); if (isIDFIRST_lazy_if(p,UTF)) { - p = scan_ident(p, PL_tokenbuf, sizeof PL_tokenbuf, TRUE); + p = scan_word(p, PL_tokenbuf, sizeof PL_tokenbuf, TRUE, &len); p = PEEKSPACE(p); } if (*p != '$') |