Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit d76a32f

Browse files
committed
Print attributes in punned record labels.
This is now produced by the printer but is a parsing error: ```rescript | {@optional name, x: 3} => 4242 ```
1 parent c31622c commit d76a32f

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

src/res_printer.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,9 +2342,10 @@ and printPatternRecordRow row cmtTbl =
23422342
match row with
23432343
(* punned {x}*)
23442344
| ( ({Location.txt = Longident.Lident ident} as longident),
2345-
{Parsetree.ppat_desc = Ppat_var {txt; _}} )
2345+
{Parsetree.ppat_desc = Ppat_var {txt; _}; ppat_attributes} )
23462346
when ident = txt ->
2347-
printLidentPath longident cmtTbl
2347+
Doc.concat
2348+
[printAttributes ppat_attributes cmtTbl; printLidentPath longident cmtTbl]
23482349
| longident, pattern ->
23492350
let locForComments =
23502351
{longident.loc with loc_end = pattern.Parsetree.ppat_loc.loc_end}
@@ -4646,7 +4647,11 @@ and printRecordRow (lbl, expr) cmtTbl punningAllowed =
46464647
| Pexp_ident {txt = Lident key; loc = _keyLoc}
46474648
when punningAllowed && Longident.last lbl.txt = key ->
46484649
(* print punned field *)
4649-
printLidentPath lbl cmtTbl
4650+
Doc.concat
4651+
[
4652+
printAttributes expr.pexp_attributes cmtTbl;
4653+
printLidentPath lbl cmtTbl;
4654+
]
46504655
| _ ->
46514656
Doc.concat
46524657
[

tests/parsing/grammar/expressions/record.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ let z = name => { name : @optional name, x: 3}
3131
let _ = switch z {
3232
| {x: @optional None, y: @optional None, z: @optional None} => 11
3333
| {name: @optional name, x: 3} => 42
34+
// | {@optional name, x: 3} => 4242
3435
}

tests/printer/expr/expected/record.res.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ let r = {a /* a */, b /* b */}
7676

7777
let r = {x: @optional None, y: @optional None, z: @optional None}
7878

79-
let z = name => {name, x: 3}
79+
let z = name => {@optional name, x: 3}
8080

8181
let _ = switch z {
8282
| {x: @optional None, y: @optional None, z: @optional None} => 11
83-
| {name, x: 3} => 42
83+
| {@optional name, x: 3} => 42
84+
| {name: @optional dd, x: 3} => 42
8485
}

tests/printer/expr/record.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,5 @@ let z = name => { name : @optional name, x: 3}
7171
let _ = switch z {
7272
| {x: @optional None, y: @optional None, z: @optional None} => 11
7373
| {name: @optional name, x: 3} => 42
74+
| {name: @optional dd, x: 3} => 42
7475
}

0 commit comments

Comments
 (0)