GetFirefly/firefly

build_primop_value does not support capture of local functions

KronicDeth opened this issue · 2 comments

fun NAME/ARITY is allowed to capture a local functions, but https://github.com/lumen/lumen/blob/5e4bb1f8ccf5f51fb44a4b0c9de264f30ae2b230/compiler/codegen/src/builder/function.rs#L1438-L1446 requires 4 reads, which makes sense for fun MODULE:FUNCTION/ARITY, but not for the local capture. This clause needs to be expanded to handle local captures too.

init.erl

-module(init).
-export([start/0]).
-import(erlang, [apply/2, display/1]).

start() ->
  from_fun().

from_fun() ->
  Fun = fun return_from_export/0,
  Return = apply(Fun, []),
  display(Return).


return_from_export() ->
  from_fun.

Even local functions should hit the 4 read path as well. If that assertion fails it's an eir bug.

@hansihe ok, I'll remove my local fix and not check it in then. I'll leave it up to you to transfer the issue or start a related bug in the EIR repo then.