In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/451f421fe4742646fa2efbed0f45a19f0713d00f?hp=73f2c082cce3e45af05f993af5e9294bb30e6ee5>
- Log ----------------------------------------------------------------- commit 451f421fe4742646fa2efbed0f45a19f0713d00f Author: Father Chrysostomos <spr...@cpan.org> Date: Wed Oct 10 13:14:31 2012 -0700 [perl #114658] Fix line numbers at the end of string eval $ perl -e 'eval "{;"; print $@' Missing right curly or square bracket at (eval 1) line 1, at end of line syntax error at (eval 1) line 1, at EOF $ perl -e 'eval "{"; print $@' Missing right curly or square bracket at (eval 1) line 2, at end of line syntax error at (eval 1) line 2, at EOF Notice how the line number goes up when there is no semicolon. What happens is that eval tacks "\n;" on to the end of the string if it does not already end with a semicolon. I actually changed this in blead in commit 11076590 to tack "\n;" on to the end all the time, to make eval "q;;" and eval "return #comment;" work. This caused the line number to increase for eval "{;". This commit fixes both examples above by modifying S_incline to account for the "\n;" at the end of a string eval. Existing tests had to be modified, as they were testing for the wrong line number. ----------------------------------------------------------------------- Summary of changes: t/lib/warnings/pad | 24 ++++++++++++------------ t/op/eval.t | 11 ++++++++++- toke.c | 6 ++++++ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/t/lib/warnings/pad b/t/lib/warnings/pad index b226239..03c4ddb 100644 --- a/t/lib/warnings/pad +++ b/t/lib/warnings/pad @@ -173,7 +173,7 @@ sub { }->(); f(); EXPECT -Variable "$x" is not available at (eval 1) line 2. +Variable "$x" is not available at (eval 1) line 1. ######## # pad.c use warnings 'closure' ; @@ -195,7 +195,7 @@ sub f { } f()->(); EXPECT -Variable "$x" is not available at (eval 1) line 2. +Variable "$x" is not available at (eval 1) line 1. ######## use warnings 'closure' ; { @@ -205,7 +205,7 @@ use warnings 'closure' ; } f2(); EXPECT -Variable "$x" is not available at (eval 1) line 2. +Variable "$x" is not available at (eval 1) line 1. ######## use warnings 'closure' ; for my $x (1,2,3) { @@ -214,7 +214,7 @@ for my $x (1,2,3) { } f(); EXPECT -Variable "$x" is not available at (eval 4) line 2. +Variable "$x" is not available at (eval 4) line 1. ######## # pad.c no warnings 'closure' ; @@ -433,7 +433,7 @@ sub { }->(); f(); EXPECT -Variable "$ã«" is not available at (eval 1) line 2. +Variable "$ã«" is not available at (eval 1) line 1. ######## # pad.c # see bugid 1754 @@ -446,7 +446,7 @@ sub f { } f()->(); EXPECT -Variable "$ã«" is not available at (eval 1) line 2. +Variable "$ã«" is not available at (eval 1) line 1. ######## use warnings 'closure' ; BEGIN { binmode STDERR, 'utf8'; } @@ -458,7 +458,7 @@ BEGIN { binmode STDERR, 'utf8'; } } f2(); EXPECT -Variable "$ã«" is not available at (eval 1) line 2. +Variable "$ã«" is not available at (eval 1) line 1. ######## use warnings 'closure' ; BEGIN { binmode STDERR, 'utf8'; } @@ -469,7 +469,7 @@ for my $ã« (1,2,3) { } f(); EXPECT -Variable "$ã«" is not available at (eval 4) line 2. +Variable "$ã«" is not available at (eval 4) line 1. ######## # pad.c use warnings 'closure' ; @@ -534,7 +534,7 @@ sub { }->(); f(); EXPECT -Variable "$è" is not available at (eval 1) line 2. +Variable "$è" is not available at (eval 1) line 1. ######## # pad.c # see bugid 1754 @@ -547,7 +547,7 @@ sub f { } f()->(); EXPECT -Variable "$è" is not available at (eval 1) line 2. +Variable "$è" is not available at (eval 1) line 1. ######## use warnings 'closure' ; BEGIN { binmode STDERR, 'utf8'; } @@ -559,7 +559,7 @@ BEGIN { binmode STDERR, 'utf8'; } } f2(); EXPECT -Variable "$è" is not available at (eval 1) line 2. +Variable "$è" is not available at (eval 1) line 1. ######## use warnings 'closure' ; BEGIN { binmode STDERR, 'utf8'; } @@ -570,5 +570,5 @@ for my $è (1,2,3) { } f(); EXPECT -Variable "$è" is not available at (eval 4) line 2. +Variable "$è" is not available at (eval 4) line 1. ######## diff --git a/t/op/eval.t b/t/op/eval.t index 9866ca7..49f7494 100644 --- a/t/op/eval.t +++ b/t/op/eval.t @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; } -plan(tests => 126); +plan(tests => 128); eval 'pass();'; @@ -609,3 +609,12 @@ pass("phew! dodged the assertion after a parsing (not lexing) error"); qr/Unbalanced string table/, 'Errors in finalize_optree do not leak string eval op tree'; } + +# [perl #114658] Line numbers at end of string eval +for("{;", "{") { + eval $_; is $@ =~ s/eval \d+/eval 1/rag, <<'EOE', +Missing right curly or square bracket at (eval 1) line 1, at end of line +syntax error at (eval 1) line 1, at EOF +EOE + qq'Right line number for eval "$_"'; +} diff --git a/toke.c b/toke.c index e9a06eb..1079e94 100644 --- a/toke.c +++ b/toke.c @@ -1559,6 +1559,12 @@ S_incline(pTHX_ const char *s) PERL_ARGS_ASSERT_INCLINE; COPLINE_INC_WITH_HERELINES; + if (!PL_rsfp && !PL_parser->filtered && PL_lex_state == LEX_NORMAL + && s+1 == PL_bufend && *s == ';') { + /* fake newline in string eval */ + CopLINE_dec(PL_curcop); + return; + } if (*s++ != '#') return; while (SPACE_OR_TAB(*s)) -- Perl5 Master Repository