(perl #132158) abort compilation if we see an error compiling a form
authorTony Cook <tony@develop-help.com>
Tue, 28 Aug 2018 04:11:10 +0000 (14:11 +1000)
committerTony Cook <tony@develop-help.com>
Thu, 3 Jan 2019 04:22:13 +0000 (15:22 +1100)
t/lib/croak/toke
toke.c

index 59c377b..2185122 100644 (file)
@@ -493,3 +493,12 @@ sub t1 {}
 sub t2 (}
 EXPECT
 Prototype not terminated at - line 2.
+########
+# NAME [perl #132158] format with syntax errors
+format=
+@
+=h
+=cut
+EXPECT
+syntax error at - line 4, next token ???
+Execution of - aborted due to compilation errors.
diff --git a/toke.c b/toke.c
index 844de04..666424b 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -5099,6 +5099,14 @@ Perl_yylex(pTHX)
 
        return yylex();
     case LEX_FORMLINE:
+        if (PL_parser->sub_error_count != PL_error_count) {
+            /* There was an error parsing a formline, which tends to
+               mess up the parser.
+               Unlike interpolated sub-parsing, we can't treat any of
+               these as recoverable, so no need to check sub_no_recover.
+            */
+            yyquit();
+        }
        assert(PL_lex_formbrack);
        s = scan_formline(PL_bufptr);
        if (!PL_lex_formbrack)
@@ -6518,6 +6526,7 @@ Perl_yylex(pTHX)
                SAVEI32(PL_lex_formbrack);
                PL_parser->form_lex_state = PL_lex_state;
                PL_lex_formbrack = PL_lex_brackets + 1;
+                PL_parser->sub_error_count = PL_error_count;
                goto leftbracket;
            }
        }