Skip to content

Keep parens on anonymous function calls with do-end blocks - #16004

Merged
josevalim merged 1 commit into
elixir-lang:mainfrom
mandar1045:fix-formatter-anonymous-call-do-block
Oct 19, 2026
Merged

josevalim merged 1 commit into
elixir-lang:mainfrom
mandar1045:fix-formatter-anonymous-call-do-block

Conversation

@mandar1045

Copy link
Copy Markdown
Contributor

Closes #16003.

The formatter printed anonymous function calls with :skip_if_do_end, so when the call had a do-end block the parens were dropped and callback.(conn, opts) do became callback. conn, opts do, which doesn't parse. In some cases like fun.(a).(b) do c end the output even parsed to something different.

For anonymous calls the parens are part of the syntax, so this now uses :required, same as the call(call)(arguments) clause right below it. Calls without a do-end block format the same as before. This also fixes Macro.to_string/1.

Added tests in calls_test.exs and quoted_ast_test.exs.

Anonymous function calls were formatted with :skip_if_do_end, which
dropped the parens when the call had a do-end block and produced code
that does not parse. Use :required instead, as the parens are part of
the anonymous call syntax.

Signed-off-by: Mandar Joshi <mandarjoshi1045@gmail.com>
@josevalim
josevalim merged commit 988b41d into elixir-lang:main Oct 19, 2026
15 checks passed
@mandar1045
mandar1045 deleted the fix-formatter-anonymous-call-do-block branch October 19, 2026 11:05
mandar1045 added a commit to mandar1045/mandarjoshi-portfolio that referenced this pull request Oct 19, 2026
Add elixir-lang/elixir#16004 (parens on anonymous calls with do-end
blocks), now merged, to the portfolio and resume.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Formatter turns anonymous function calls with a do block into invalid code

2 participants