Skip to content

Fix fmt dropping parens of called arrow lambda#9380

Open
realugi wants to merge 1 commit intoroc-lang:mainfrom
realugi:fix-9372
Open

Fix fmt dropping parens of called arrow lambda#9380
realugi wants to merge 1 commit intoroc-lang:mainfrom
realugi:fix-9372

Conversation

@realugi
Copy link
Copy Markdown
Contributor

@realugi realugi commented Apr 28, 2026

fixes #9372

consider fmt on this expr:

1->(|x| x)()

before:

1->|x| x()

after:

1->(|x| x)()

Copy link
Copy Markdown
Collaborator

@Anton-4 Anton-4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@realugi
Copy link
Copy Markdown
Contributor Author

realugi commented Apr 30, 2026

Sounds reasonable.

We should consider the following edge cases though:

10->(|x, _| x + 1)() # 1
10->(|x| x + 1)(11) # 2

1: 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)()
~~~
@Anton-4
Copy link
Copy Markdown
Collaborator

Anton-4 commented May 1, 2026

That sounds good @realugi :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formatter Bug: drops parenthesis of called, arrow-dispatched, inline lambda

2 participants