Skip to content

Commit 8a2753e

Browse files
committed
Fix some comments disappearing in array sugar.
The ids for `Array.get` and `Array.set` used to desugar array access have location that overlaps with the arguments, stealing the comments. This takes care of some examples similar to the one in #5946 but not that specific example.
1 parent 705b1c9 commit 8a2753e

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

res_syntax/src/res_core.ml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,7 +1976,6 @@ and parseFirstClassModuleExpr ~startPos p =
19761976

19771977
and parseBracketAccess p expr startPos =
19781978
Parser.leaveBreadcrumb p Grammar.ExprArrayAccess;
1979-
let lbracket = p.startPos in
19801979
Parser.expect Lbracket p;
19811980
let stringStart = p.startPos in
19821981
match p.Parser.token with
@@ -2009,20 +2008,18 @@ and parseBracketAccess p expr startPos =
20092008
let accessExpr = parseConstrainedOrCoercedExpr p in
20102009
Parser.expect Rbracket p;
20112010
Parser.eatBreadcrumb p;
2012-
let rbracket = p.prevEndPos in
2013-
let arrayLoc = mkLoc lbracket rbracket in
20142011
match p.token with
20152012
| Equal ->
20162013
Parser.leaveBreadcrumb p ExprArrayMutation;
20172014
Parser.next p;
20182015
let rhsExpr = parseExpr p in
20192016
let arraySet =
2020-
Location.mkloc (Longident.Ldot (Lident "Array", "set")) arrayLoc
2017+
Location.mknoloc (Longident.Ldot (Lident "Array", "set"))
20212018
in
20222019
let endPos = p.prevEndPos in
20232020
let arraySet =
20242021
Ast_helper.Exp.apply ~loc:(mkLoc startPos endPos)
2025-
(Ast_helper.Exp.ident ~loc:arrayLoc arraySet)
2022+
(Ast_helper.Exp.ident arraySet)
20262023
[(Nolabel, expr); (Nolabel, accessExpr); (Nolabel, rhsExpr)]
20272024
in
20282025
Parser.eatBreadcrumb p;
@@ -2031,8 +2028,8 @@ and parseBracketAccess p expr startPos =
20312028
let endPos = p.prevEndPos in
20322029
let e =
20332030
Ast_helper.Exp.apply ~loc:(mkLoc startPos endPos)
2034-
(Ast_helper.Exp.ident ~loc:arrayLoc
2035-
(Location.mkloc (Longident.Ldot (Lident "Array", "get")) arrayLoc))
2031+
(Ast_helper.Exp.ident
2032+
(Location.mknoloc (Longident.Ldot (Lident "Array", "get"))))
20362033
[(Nolabel, expr); (Nolabel, accessExpr)]
20372034
in
20382035
parsePrimaryExpr ~operand:e p)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
a[ /* zz */ 0 ] = 7
2+
3+
let _ = (
4+
/* zz */ a
5+
)[0]
6+
7+
let _ = (
8+
a // zz
9+
)[0]
10+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
a[/* zz */ 0] = 7
2+
3+
let _ = /* zz */ a[0]
4+
5+
let _ = a[0] // zz

0 commit comments

Comments
 (0)