Skip to content

Commit b21f017

Browse files
committed
fix regex literal loc
1 parent cea6328 commit b21f017

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

compiler/syntax/src/res_core.ml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,15 @@ and parse_constrained_expr_region p =
18151815
and parse_regex p pattern flags =
18161816
let start_pos = p.Parser.start_pos in
18171817
Parser.next p;
1818-
let loc = mk_loc start_pos p.prev_end_pos in
1818+
let loc =
1819+
mk_loc
1820+
{
1821+
start_pos with
1822+
(* Account for the inserted leading `/` *)
1823+
pos_cnum = start_pos.pos_cnum - 1;
1824+
}
1825+
p.prev_end_pos
1826+
in
18191827
let payload =
18201828
Parsetree.PStr
18211829
[
@@ -1826,7 +1834,7 @@ and parse_regex p pattern flags =
18261834
if p.mode = ParseForTypeChecker then Some "js" else None )));
18271835
]
18281836
in
1829-
Ast_helper.Exp.extension (Location.mknoloc "re", payload)
1837+
Ast_helper.Exp.extension (Location.mkloc "re" loc, payload)
18301838

18311839
(* Atomic expressions represent unambiguous expressions.
18321840
* This means that regardless of the context, these expressions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

22
We've found a bug for you!
3-
/.../fixtures/extract_from_none_file.res
3+
/.../fixtures/regex_literal.res:1:7-11
4+
5+
1 │ while /foo/ {
6+
2 │ ()
7+
3 │ }
48

59
This has type: RegExp.t
610
But a while loop condition must always be of type: bool

tests/build_tests/super_errors/fixtures/extract_from_none_file.res

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
while /foo/ {
2+
()
3+
}

0 commit comments

Comments
 (0)