Fix fmt dropping parens of called arrow lambda#9380
Fix fmt dropping parens of called arrow lambda#9380realugi wants to merge 1 commit intoroc-lang:mainfrom
Conversation
Anton-4
left a comment
There was a problem hiding this comment.
Thanks for the contribution @realugi :)
On first thought I feel like the formatter should remove the (), so:
10->(|x| x + 1)()
Becomes:
10->(|x| x + 1)
Because the () are not necessary for correctness and all other things being equal, less code is better but feel free to share your opinion on this.
|
Sounds reasonable. We should consider the following edge cases though: 10->(|x, _| x + 1)() # 1
10->(|x| x + 1)(11) # 21: For lambdas with more than one argument, keeping the empty parenthesis sounds like a more sensible decision. If I had to argue, I would say that dropping the empty parenthesis in this case would induce more work for the programmer, since they have to include the parenthesis for type-safe code anyway. 2: For lambdas containing too many arguments, I would also keep the parenthesis with its content, because the error in the snippet might be, that the lambda should accept more parameters. Also relevant might be the fact, that we add empty parenthesis on arrow-dispatched idents (see this snapshot test, the behavior of which was introduced in this commit). However, I do believe the inline lambda case is different enough to warrant special casing in the formatter. |
consider fmt on this expr: ~~~ 1->(|x| x)() ~~~ before: ~~~ 1->|x| x() ~~~ after: ~~~ 1->(|x| x)() ~~~
|
That sounds good @realugi :) |
fixes #9372
consider fmt on this expr:
before:
after: