I came across this issue when using a behaviour from a dependency and did not see any warnings when I implemented a callback with the wrong number of arguments. I used mix run --no-mix-exs script.exs
. Reproducible on 1.15.7 but works as expected on 1.13.4.
Here’s an MRE:
defmodule MyBehaviour do
@callback my_fun(arg :: any) :: any
end
defmodule MyModule do
@behaviour MyBehaviour
@impl true
def my_fub(arg) do
arg
end
end
IO.puts("Hello world")
Output using 1.13.4 and 1.15.7:
root@5da670a83b2e:/workspace/my_project# mix run --no-mix-exs script.exs
warning: got "@impl true" for function my_fub/1 but no behaviour specifies such callback. The known callbacks are:
* MyBehaviour.my_fun/1 (function)
script.exs:9: MyModule (module)
warning: function my_fun/1 required by behaviour MyBehaviour is not implemented (in module MyModule)
script.exs:5: MyModule (module)
Hello world
root@5da670a83b2e:/workspace/my_project#
With receive
block:
defmodule MyBehaviour do
@callback my_fun(arg :: any) :: any
end
defmodule MyModule do
@behaviour MyBehaviour
@impl true
def my_fub(arg) do
arg
end
end
IO.puts("Hello world")
receive do
:done -> MyModule.my_fub("Hello again")
end
Output using both versions:
root@5da670a83b2e:/workspace/my_project# asdf global elixir 1.13
root@5da670a83b2e:/workspace/my_project# mix run --no-mix-exs script.exs
warning: got "@impl true" for function my_fub/1 but no behaviour specifies such callback. The known callbacks are:
* MyBehaviour.my_fun/1 (function)
script.exs:9: MyModule (module)
warning: function my_fun/1 required by behaviour MyBehaviour is not implemented (in module MyModule)
script.exs:5: MyModule (module)
Hello world
^C
BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo
(l)oaded (v)ersion (k)ill (D)b-tables (d)istribution
a
root@5da670a83b2e:/workspace/my_project# asdf global elixir 1.15.7
root@5da670a83b2e:/workspace/my_project# mix run --no-mix-exs script.exs
Hello world
I’d be grateful for any help, cheers