@@ -2807,19 +2807,19 @@ and printExpression (e : Parsetree.expression) cmtTbl =
2807
2807
let forceBreak =
2808
2808
e.pexp_loc.loc_start.pos_lnum < e.pexp_loc.loc_end.pos_lnum
2809
2809
in
2810
- let punningAllowed = match spreadExpr, rows with
2811
- | (None, [_ ]) -> false (* disallow punning for single-element records *)
2812
- | _ -> true
2813
- in
2814
2810
Doc. breakableGroup ~force Break (
2815
2811
Doc. concat([
2816
2812
Doc. lbrace;
2817
2813
Doc. indent (
2818
2814
Doc. concat [
2819
2815
Doc. softLine;
2820
- spread;
2821
- Doc. join ~sep: (Doc. concat [Doc. text " ," ; Doc. line])
2822
- (List. map (fun row -> printRecordRow row cmtTbl punningAllowed) rows)
2816
+ match spreadExpr, rows with
2817
+ | (None, [row ]) -> printRecordRowNoPunning row cmtTbl
2818
+ | _ -> Doc. concat [
2819
+ spread;
2820
+ Doc. join ~sep: (Doc. concat [Doc. text " ," ; Doc. line])
2821
+ (List. map (fun row -> printRecordRow row cmtTbl) rows)
2822
+ ]
2823
2823
]
2824
2824
);
2825
2825
Doc. trailingComma;
@@ -4822,19 +4822,15 @@ and printDirectionFlag flag = match flag with
4822
4822
| Asttypes. Downto -> Doc. text " downto "
4823
4823
| Asttypes. Upto -> Doc. text " to "
4824
4824
4825
- and printRecordRow (lbl , expr ) cmtTbl punningAllowed =
4825
+ and printRecordRowPunned (lbl , expr ) cmtTbl =
4826
+ let cmtLoc = {lbl.Asttypes. loc with loc_end = expr.Parsetree. pexp_loc.loc_end} in
4827
+ let doc = Doc. group (printLidentPath lbl cmtTbl) in
4828
+ printComments doc cmtTbl cmtLoc
4829
+
4830
+ and printRecordRowNoPunning (lbl , expr ) cmtTbl =
4826
4831
let cmtLoc = {lbl.loc with loc_end = expr.pexp_loc.loc_end} in
4827
4832
let doc = Doc. group (
4828
- match expr.pexp_desc with
4829
- | Pexp_ident ({txt = Lident key; loc = keyLoc}) when (
4830
- punningAllowed &&
4831
- Longident. last lbl.txt = key &&
4832
- lbl.loc.loc_start.pos_cnum == keyLoc.loc_start.pos_cnum
4833
- ) ->
4834
- (* print punned field *)
4835
- printLidentPath lbl cmtTbl;
4836
- | _ ->
4837
- Doc. concat [
4833
+ Doc. concat [
4838
4834
printLidentPath lbl cmtTbl;
4839
4835
Doc. text " : " ;
4840
4836
(let doc = printExpressionWithComments expr cmtTbl in
@@ -4846,6 +4842,14 @@ and printRecordRow (lbl, expr) cmtTbl punningAllowed =
4846
4842
) in
4847
4843
printComments doc cmtTbl cmtLoc
4848
4844
4845
+ and printRecordRow (lbl , expr ) cmtTbl =
4846
+ match expr.pexp_desc with
4847
+ | Pexp_ident ({txt = Lident key; loc = keyLoc}) when (
4848
+ Longident. last lbl.txt = key &&
4849
+ lbl.loc.loc_start.pos_cnum == keyLoc.loc_start.pos_cnum
4850
+ ) -> printRecordRowPunned (lbl, expr) cmtTbl;
4851
+ | _ -> printRecordRowNoPunning (lbl, expr) cmtTbl
4852
+
4849
4853
and printBsObjectRow (lbl , expr ) cmtTbl =
4850
4854
let cmtLoc = {lbl.loc with loc_end = expr.pexp_loc.loc_end} in
4851
4855
let lblDoc =
0 commit comments