ensure qw//, q'' and '' report line on a missing terminator
authorTony Cook <tony@develop-help.com>
Tue, 6 May 2014 23:33:03 +0000 (09:33 +1000)
committerKarl Williamson <khw@cpan.org>
Mon, 12 May 2014 19:07:04 +0000 (13:07 -0600)
scan_str() only sets PL_multi_end on success, but the qw, q amd '' cases
were calling the COPLINE_SET_FROM_MULTI_END; macro before reporting
failure, overwriting the line used for reporting errors.

For the simplest case, as in the ticket and the tests, PL_multi_end is
zero, so the error is reported without a line number.

t/lib/croak/toke
toke.c

index d6026d2..0572094 100644 (file)
@@ -134,3 +134,18 @@ Execution of - aborted due to compilation errors.
 <<"foo
 EXPECT
 Unterminated delimiter for here document at - line 1.
+########
+# NAME Unterminated qw//
+qw/
+EXPECT
+Can't find string terminator "/" anywhere before EOF at - line 1.
+########
+# NAME Unterminated q//
+qw/
+EXPECT
+Can't find string terminator "/" anywhere before EOF at - line 1.
+########
+# NAME Unterminated ''
+'
+EXPECT
+Can't find string terminator "'" anywhere before EOF at - line 1.
diff --git a/toke.c b/toke.c
index 3d992f6..ea88183 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -6848,6 +6848,8 @@ Perl_yylex(pTHX)
 
     case '\'':
        s = scan_str(s,!!PL_madskills,FALSE,FALSE,FALSE,NULL);
+       if (!s)
+           missingterm(NULL);
        COPLINE_SET_FROM_MULTI_END;
        DEBUG_T( { printbuf("### Saw string before %s\n", s); } );
        if (PL_expect == XOPERATOR) {
@@ -6857,8 +6859,6 @@ Perl_yylex(pTHX)
            else
                no_op("String",s);
        }
-       if (!s)
-           missingterm(NULL);
        pl_yylval.ival = OP_CONST;
        TERM(sublex_start());
 
@@ -8385,9 +8385,9 @@ Perl_yylex(pTHX)
 
        case KEY_q:
            s = scan_str(s,!!PL_madskills,FALSE,FALSE,FALSE,NULL);
-           COPLINE_SET_FROM_MULTI_END;
            if (!s)
                missingterm(NULL);
+           COPLINE_SET_FROM_MULTI_END;
            pl_yylval.ival = OP_CONST;
            TERM(sublex_start());
 
@@ -8397,9 +8397,9 @@ Perl_yylex(pTHX)
        case KEY_qw: {
            OP *words = NULL;
            s = scan_str(s,!!PL_madskills,FALSE,FALSE,FALSE,NULL);
-           COPLINE_SET_FROM_MULTI_END;
            if (!s)
                missingterm(NULL);
+           COPLINE_SET_FROM_MULTI_END;
            PL_expect = XOPERATOR;
            if (SvCUR(PL_lex_stuff)) {
                int warned_comma = !ckWARN(WARN_QW);