Closed pdgonzalez872 closed 4 years ago
This is not a formatter bug, the formatter is actually revealing the bug in your code! |>
has higher precedence than &
, which means that:
&@implementation.make_call/2 |> function_a([args, %{}]) |> function_b()
Is actually the same as:
&(@implementation.make_call/2 |> function_a([args, %{}]) |> function_b())
What you want is to write this:
(&@implementation.make_call/2)
|> function_a([args, %{}])
|> function_b()
And everything should be good!
In any case, thank you for the great report and the nice words! Have a great weekend! :heart:
Ahh, awesome! Thank you @josevalim !
Environment
Elixir 1.9.1 (compiled with Erlang/OTP 20)
without piping twice:
def call(args) do function_a(&@implementation.make_call/2, [args, %{}]) |> function_b() end
attempt to pipe, due to Credo raw value check/suggestion:
def call(args) do &@implementation.make_call/2 |> function_a([args, %{}]) |> function_b() end
Run
mix format
, this is the output:def call(args) do &((@implementation.make_call / 2) |> function_a([args, %{}]) |> function_b()) end
try
mix compile
:== Compilation error in file lib/formatter_issue.ex == ** (CompileError) lib/formatter_issue.ex:31: invalid args for &, expected an expression in the format of &Mod.fun/arity, &local/arity or a capture containing at least one argument as &1, got: @implementation.make_call() / 2 |> function_a([args, %{}]) |> function_b()
"fix it", then run
mix format
, output:def call(args) do fun = &@implementation.make_call/2 fun |> function_a([args, %{}]) |> function_b() end