Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting fails with binary pattern match macro #357

Open
eproxus opened this issue Aug 23, 2024 · 3 comments
Open

Formatting fails with binary pattern match macro #357

eproxus opened this issue Aug 23, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@eproxus
Copy link

eproxus commented Aug 23, 2024

When formatting a module containing a macro with an argument that is put inside a binary, a compilation error is generated:

-module(my_module).

-export([func/2]).

-define(BIN(Arg), <<Arg>>).

func(uuid, ?BIN(A:8)) -> A.

Running rebar3 fmt on this file generates the following error:

$ rebar3 fmt src/my_module.erl
===> Analyzing applications...
===> Compiling erlfmt
src/my_module.erl:7:18: syntax error before: ':'

Erlang / Rebar 3 itself can compile the file just fine:

$ rebar3 shell
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling my_app
Erlang/OTP 27 [erts-15.0.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit]

Eshell V15.0.1 (press Ctrl+G to abort, type help(). for help)
1> my_module:func(<<"A">>).
65

erlfmt version: 1.3.0 and latest main
Erlang/OTP: 27.0.1
Rebar 3: 3.23.0

@michalmuskala
Copy link
Member

This is somewhat expected - erlfmt generally expects macro definitions and arguments to be valid Erlang AST, with some extensions - this is not true of a stand-alone A:8 expression.

It might be possible to extend the grammar to accept this as a stand-alone expression, but I'm not sure. This is primarily because parsing of : is already one of the most complex parts of the parser - given it has completely different precedence in all 3 places: when used as a remote call marker, in binaries, and in catch clauses.

@michalmuskala michalmuskala added the enhancement New feature or request label Aug 23, 2024
@eproxus
Copy link
Author

eproxus commented Sep 17, 2024

@michalmuskala Thanks for explaining. Feel free to close this as "won't fix" if it is not on the roadmap 😊

@Yokolora
Copy link

README.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants