Skip to content

Commit

Permalink
Respect keep_errors flag in Parser_hack for lexer errors
Browse files Browse the repository at this point in the history
Summary:
Random crash I encountered while testing unrelated changes.

Parser_hack has it's own error system, which then feeds (or not, depending on ~keep_errors) flag into global Errors module. But Parse_hack also calls into lexer, which has direct calls to Errors:

diffusion/FBS/browse/master/fbcode/hphp/hack/src/parser/lexer_hack.mll$498,513,522,530,540,548,573,617

effectively bypassing keep_errors.

Reviewed By: jamesjwu

Differential Revision: D6393239

fbshipit-source-id: 0fa86300763f836ffcd0700a22a78e415cce9a20
  • Loading branch information
dabek authored and hhvm-bot committed Dec 12, 2017
1 parent 12ffb1d commit 5ea6824
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
20 changes: 14 additions & 6 deletions hphp/hack/src/parser/parser_hack.ml
Expand Up @@ -459,15 +459,23 @@ let rec program
?(include_line_comments = false)
?(keep_errors = true)
popt file content =

let with_lexer_errors f =
if keep_errors then f () else Errors.ignore_ f in

L.include_line_comments := include_line_comments;
L.comment_list := [];
L.fixmes := IMap.empty;
let lb = Lexing.from_string content in
let env = init_env file lb popt quick in
let file_type, ast, file_mode = header env in
let is_hh_file = file_type = FileInfo.HhFile in
let comments = !L.comment_list in
let fixmes = !L.fixmes in
let env, fixmes, ast, file_mode, comments, is_hh_file =
with_lexer_errors begin fun () ->
let lb = Lexing.from_string content in
let env = init_env file lb popt quick in
let file_type, ast, file_mode = header env in
let is_hh_file = file_type = FileInfo.HhFile in
let comments = !L.comment_list in
let fixmes = !L.fixmes in
env, fixmes, ast, file_mode, comments, is_hh_file
end in
L.comment_list := [];
L.fixmes := IMap.empty;
if keep_errors then begin
Expand Down
3 changes: 3 additions & 0 deletions hphp/hack/test/outline/lexer_error.php
@@ -0,0 +1,3 @@
<?hh

/* HH_FIXME[1

0 comments on commit 5ea6824

Please sign in to comment.