Skip to content

Commit b19df94

Browse files
authored
fix(compiler): Supply correct locations for attributes (#2048)
1 parent 5f44d4e commit b19df94

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

compiler/src/parsing/parser.mly

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,10 @@ attribute_arguments:
555555
| lparen lseparated_list(comma, attribute_argument) rparen { $2 }
556556

557557
attribute:
558-
| AT id_str loption(attribute_arguments) opt_eols { Attribute.mk ~loc:(to_loc $loc) $2 $3 }
558+
| AT id_str loption(attribute_arguments) { Attribute.mk ~loc:(to_loc $loc) $2 $3 }
559559

560560
attributes:
561-
| attribute* { $1 }
561+
| terminated(attribute, opt_eols)* { $1 }
562562

563563
let_expr:
564564
| attributes LET REC value_binds { Expression.let_ ~loc:(to_loc $sloc) ~core_loc:(to_loc (fst $loc($2), snd $loc)) ~attributes:$1 Recursive Immutable $4 }

compiler/test/grainfmt/comments.expected.gr

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,16 +330,15 @@ foo += /* foo */ /* foo */ 1
330330
foo += /* foo */ /* foo */ 1
331331

332332
{
333-
@attr
333+
@attr // foo
334334
let // foo
335335
_ = 1
336336
@attr(
337337
"foo", /* doo */
338338
"foo",
339339
// foo
340340
// goo
341-
// bar
342-
)
341+
) // bar
343342
let /* doo */ // foo
344343
// goo
345344
// bar
@@ -599,15 +598,14 @@ provide {
599598
module Foo as /* Foo */ /* as */ Bar,
600599
}
601600

602-
@attr
601+
@attr // foo
603602
let _ = 1
604603
@attr(
605604
"foo", /* doo */
606605
"foo",
607606
// foo
608607
// goo
609-
// bar
610-
)
608+
) // bar
611609
let _ = 1
612610

613611
provide /* provide */ enum Foo {

0 commit comments

Comments
 (0)