Skip to content

Commit 46ff3b4

Browse files
authored
Fix location of string constants (#1574)
from ocaml/string-lit-loc
2 parents 9eecab4 + 35bc27f commit 46ff3b4

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ unreleased
1616
- Fix `construct` results ordering for sum types sand poly variants (#1603)
1717
- Fix object method completion not working (#1606, fixes #1575)
1818
- Improve context detection for package types (#1608, fixes #1607)
19+
- Fix incorrect locations for string literals (#1574)
1920
+ editor modes
2021
- emacs: call the user's configured completion UI in
2122
`merlin-construct` (#1598)

src/ocaml/preprocess/lexer_raw.mll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ let wrap_string_lexer f state lexbuf =
174174
state.string_start_loc <- Location.curr lexbuf;
175175
f state lexbuf >>= fun loc_end ->
176176
lexbuf.lex_start_p <- state.string_start_loc.Location.loc_start;
177-
state.string_start_loc <- Location.none;
178177
let loc =
179178
Location.{
180179
loc_ghost = false;
181-
loc_start = state.string_start_loc.Location.loc_start;
180+
loc_start = state.string_start_loc.Location.loc_end;
182181
loc_end;
183182
}
184183
in
184+
state.string_start_loc <- Location.none;
185185
return (Buffer.contents state.buffer, loc)
186186

187187
(* to translate escape sequences *)

tests/test-dirs/string-loc.t

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Ensure the Pexp_constant and Pconst_string nodes have different locations.
2+
3+
$ echo ' "test"' | $MERLIN single dump -what parsetree -filename test.ml
4+
{
5+
"class": "return",
6+
"value": "[
7+
structure_item (test.ml[1,0+4]..[1,0+10])
8+
Pstr_eval
9+
expression (test.ml[1,0+4]..[1,0+10])
10+
Pexp_constant PConst_string(\"test\",(test.ml[1,0+5]..[1,0+9]),None)
11+
]
12+
13+
14+
",
15+
"notifications": []
16+
}

0 commit comments

Comments
 (0)