Range for `TypeAnnotation.Record` is wrong/inconsisent
SiriusStarr opened this issue · 1 comments
The three places "records" can appear are TypeAnnotation.Record
, Expression.RecordExpr
, and Pattern.RecordPattern
. The ranges associated with TypeAnnotation.Record
, however, are inconsistent with the others, as the Node
s include the separating commas, unlike the other two.
Running
import Elm.Parser exposing (parse)
parse """module A exposing (..)
a : { b : Int, c : Int, a : Int }
a = { b = 123, c = 321, a = 223 }
b { b, c, a } = 0
"""
we get (eliminating the cruft):
Record
[ Node { end = { column = 14, row = 2 }, start = { column = 7, row = 2 } } (...)
, Node { end = { column = 23, row = 2 }, start = { column = 14, row = 2 } } (...)
, Node { end = { column = 33, row = 2 }, start = { column = 23, row = 2 } } (...)
]
RecordExpr
[ Node { end = { column = 14, row = 3 }, start = { column = 7, row = 3 } } (...)
, Node { end = { column = 23, row = 3 }, start = { column = 16, row = 3 } } (...)
, Node { end = { column = 33, row = 3 }, start = { column = 25, row = 3 } } (...)
]
RecordPattern
[ Node { end = { column = 6, row = 4 }, start = { column = 5, row = 4 } } "b"
, Node { end = { column = 9, row = 4 }, start = { column = 8, row = 4 } } "c"
, Node { end = { column = 12, row = 4 }, start = { column = 11, row = 4 } } "a"
]
Placing < >
around the node ranges in the original source:
module A exposing (..)
a : { <b : Int><, c : Int><, a : Int >}
a = { <b = 123>, <c = 321>, <a = 223 >}
b { <b>, <c>, <a> } = 0
The behavior should probably be the same between the three cases, and this current behavior causes issues with elm-review
, as the extracted source includes commas (which creates issues when they get moved around).
It should be noted that this does not occur with TypeAnnotation.GenericRecord
, with which the nodes do not include commas:
import Elm.Parser exposing (parse)
parse """module A exposing (..)
a : { r | b : Int, c : Int, a : Int }
a r = { r | b = 123, c = 321, a = 223 }
"""
yields
GenericRecord (Node { end = { column = 10, row = 2 }, start = { column = 9, row = 2 } } "r")
(Node { end = { column = 39, row = 2 }, start = { column = 12, row = 2 } }
[ Node { end = { column = 20, row = 2 }, start = { column = 13, row = 2 } } (...)
, Node { end = { column = 29, row = 2 }, start = { column = 22, row = 2 } } (...)
, Node { end = { column = 39, row = 2 }, start = { column = 31, row = 2 } } (...)
]
)
RecordUpdateExpression (Node { end = { column = 10, row = 3 }, start = { column = 9, row = 3 } } "r")
[ Node { end = { column = 20, row = 3 }, start = { column = 13, row = 3 } } (...)
, Node { end = { column = 29, row = 3 }, start = { column = 22, row = 3 } } (...)
, Node { end = { column = 39, row = 3 }, start = { column = 31, row = 3 } } (...)
]