Skip to content

Commit

Permalink
khepri_fun: Handle erl_eval source code structure changes
Browse files Browse the repository at this point in the history
In Erlang 25, it looks like the source code if the function is the
anonymous function environment is stored slightly differently.

It's easy to support both the old and the new tuples and extract that
source code.
  • Loading branch information
dumbbell committed Apr 20, 2022
1 parent e7695b6 commit 66a8e2b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/khepri_fun.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1335,9 +1335,18 @@ find_function(
BeamFileRecord :: #beam_file_ext{}.
%% @private

erl_eval_fun_to_asm(Module, Name, Arity, [{_, Bindings, _, _, _, Clauses}])
when Bindings =:= [] orelse %% Erlang is using a list for bindings,
Bindings =:= #{} -> %% but Elixir is using a map.
%% Erlang starting from 25.
erl_eval_fun_to_asm1(Module, Name, Arity, Clauses);
erl_eval_fun_to_asm(Module, Name, Arity, [{Bindings, _, _, Clauses}])
when Bindings =:= [] orelse %% Erlang is using a list for bindings,
Bindings =:= #{} -> %% but Elixir is using a map.
%% Erlang up to 24.
erl_eval_fun_to_asm1(Module, Name, Arity, Clauses).

erl_eval_fun_to_asm1(Module, Name, Arity, Clauses) ->
%% We construct an abstract form based on the `env' of the lambda loaded
%% by `erl_eval'.
Anno = erl_anno:from_term(1),
Expand Down

0 comments on commit 66a8e2b

Please sign in to comment.