-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Reason] Semicolon is not required after final item in sequence.
Summary:Per request of @jberdine, we no longer require the final semicolon. There's a small tradeoff that had to be made (no punned, single item records) - but that case is very rare, and would surely be caught by the type system. I also took the opportunity to start a clean directory of type checked formatting test cases. Many bugs in parsing/printing would be caught by simple type checking of the AST. Thanks for the suggesion, Josh. I like this much better. The next step is to make it so when pretty printing, the final semicolon is ommitted. Similarly, it is easy to make it such that the final item in a module/signature does not require a semicolon. Test Plan:Added type-checked formatting tests. Reviewers:@jberdine, @cristianoc CC:
- Loading branch information
Showing
7 changed files
with
184 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
typeCheckedTests/*.out | ||
typeCheckedTests/*.cmo | ||
typeCheckedTests/*.cmi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
let result = { | ||
let twenty = 20; | ||
let result = twenty; | ||
result; | ||
}; | ||
|
||
/* Final semicolon is not required */ | ||
let result = { | ||
let twenty = result; | ||
twenty | ||
}; | ||
let anInt = result + 20; | ||
|
||
let twenty = 20; | ||
|
||
/** | ||
* Each of these are a sequence with a single item - they will be | ||
* printed in reduced form because sequences are a *parse* time construct. | ||
* To ensure these are parsed correctly, adding to an integer. | ||
*/ | ||
let result = 0 + {twenty}; | ||
let result = 0 + {twenty;}; | ||
let result = 0 + twenty; | ||
|
||
let unitValue = (); | ||
/* While loops/for loops merely accept a "simple expression" (which means | ||
* it is either a simple token or balanced with parens/braces). However, | ||
* the formatter ensures that the bodies are printed in "sequence" form even if | ||
* it's not required. | ||
*/ | ||
while false unitValue; | ||
while (false) { | ||
print_string "test" | ||
}; | ||
while (false) { | ||
print_string "test"; | ||
}; | ||
|
||
type myRecord = { | ||
number: int | ||
}; | ||
let x = {number:20}; | ||
let number = 20; | ||
/* | ||
* The (mild) consequence of not requiring a final semi in a sequence, | ||
* is that we can no longer "pun" a single field record (which would) | ||
* be very rare anyways. | ||
*/ | ||
let cannotPunASingleFieldRecord = {number: number}; | ||
let fourty = 20 + cannotPunASingleFieldRecord.number; | ||
let thisIsASequenceNotPunedRecord = {number}; | ||
let fourty = 20 + thisIsASequenceNotPunedRecord; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3a722c2
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.
3a722c2
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.
3a722c2
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.
Regarding line breaking behavior: Here is the issue for
Easy_format
that will allow this: ocaml-community/easy-format#23a722c2
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.
@jberdine:
Yes, that is the tradeoff. If it's an annoyance, we can always roll back this change and automatically reformat all existing code back to the way it was. I'll explain a few more reasons why I wasn't super concerned:
3a722c2
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.