Skip to content

Commit 8a8a906

Browse files
authored
feat(compiler): Correct lexer error in malformed match (#2370)
1 parent 126a4c4 commit 8a8a906

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

compiler/src/parsing/wrapped_lexer.re

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,30 @@ let token = state => {
437437
triple;
438438
};
439439
};
440+
441+
let print_syntax_error =
442+
Printf.(
443+
Location.(
444+
fun
445+
| Lex_fast_forward_failed(acc, None) => {
446+
let loc =
447+
switch (List.rev(acc)) {
448+
| [_, (tkn, loc_start, loc_end), ..._] => {
449+
loc_start,
450+
loc_end,
451+
loc_ghost: false,
452+
}
453+
| [(tkn, loc_start, loc_end), ..._] => {
454+
loc_start,
455+
loc_end,
456+
loc_ghost: false,
457+
}
458+
| [] => Location.dummy_loc
459+
};
460+
Some(errorf(~loc, "Syntax error."));
461+
}
462+
| _ => None
463+
)
464+
);
465+
466+
let _ = Location.register_error_of_exn(print_syntax_error);

compiler/test/suites/parsing.re

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,4 +563,7 @@ describe("parsing", ({test, testSkip}) => {
563563
prog_core_loc: Location.dummy_loc,
564564
},
565565
);
566+
// Regression for #2369
567+
assertCompileError("lexer_hack_match_1", "(match { })", "Syntax error.");
568+
assertCompileError("lexer_hack_match_2", "(match (true)", "Syntax error.");
566569
});

0 commit comments

Comments
 (0)