spawn/1 with 1-arity function gets passed the closure itself as the first argument and does not error badarity
Closed this issue · 3 comments
init.erl
-module(init).
-export([start/0]).
-import(erlang, [display/1]).
-import(lumen, [is_big_integer/1, is_small_integer/1]).
start() ->
ChildPid = spawn(fun (A) ->
display(A)
end),
MonitorRef = monitor(process, ChildPid),
receive
{'DOWN', MonitorRef, process, _, Info} ->
display(Info)
after 20 ->
display(timeout)
end,
ok.
Output
&init."0-0-b7cf7a7fbde801f90000000000000000"/1
normal
This is probably happening because of the environment being passed as the first argument, but the environment is passed as the closure as a term, which is why it is printed. If instead of invoking the closure's callee()
directly, instead apply/2
is called with [closure, []]
as the environment, then apply/2
will error out before the closure is called.
This isn’t actually a compiler issue if I understand correctly. Closures get called correctly in the generated code, but the problem is that apply/2 should be appending the env to the closure called, rather than having the caller of apply pass the closure as an argument, and thus assuming that there is an arity mismatch.
@bitwalker I agree, it’s not compiler. I can fix it runtime only. Doing that tomorrow.