-
Notifications
You must be signed in to change notification settings - Fork 38
Print punned fields #480
Print punned fields #480
Conversation
|
||
// Punning | ||
let r = {a} // actually not a record, just an expression in braces | ||
let r = {a, b} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add an extra test case with all kind of different comments on punned key-values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some, looks good to me.
@@ -2815,7 +2819,7 @@ and printExpression (e : Parsetree.expression) cmtTbl = | |||
Doc.softLine; | |||
spread; | |||
Doc.join ~sep:(Doc.concat [Doc.text ","; Doc.line]) | |||
(List.map (fun row -> printRecordRow row cmtTbl) rows) | |||
(List.map (fun row -> printRecordRow row cmtTbl punningAllowed) rows) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing punningAllowed
to every row, would it be "clearer" if we special cased the one-element record?
// pseudo-code
if (one-element-record) {
…
} else {
List.map printRecordRow…
}
What do you think about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tried that here: cknitt@d83c61f
Do you think it is an improvement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cknitt Thanks for the improvements, good to ship! Sorry for the delay.
Currently, the printer removes record field punning as discussed in #252 (for record expressions) and #47 (for record type declarations). I.e., it expands
{a, b}
to{a: a, b: b}
.I gather from the discussions that we want to leave the behavior for record type declarations as it is, but improve the behavior for record expressions. This PR addresses that.
To avoid breaking changes for now, the printer will keep record expressions as the user wrote them, whether punned or not. That is,
{a, b}
will remain{a, b}
and{a: a, b: b}
will remain{a: a, b: b}
.