power_shell icon indicating copy to clipboard operation
power_shell copied to clipboard

confusing error message when eval'ed function calls an undefined function

Open zerth opened this issue 4 years ago • 1 comments

-module(thingy).
-export([x/0]).
x() ->
  lists:foldl(fun (E, A) -> some_mod:xyz(E, A) end, [], [1, 2, 3]).
1> c(thingy),power_shell:eval(thingy,x,[]).
** exception error: undefined function lists:foldl/3
     in function  lists:foldl/3
     in call from thingy:x/0

zerth avatar Nov 22 '21 22:11 zerth

This seems due to the way the anonymous function is being evaluated after being passed to a built-in function (in this case lists:foldl/3):

-module(thiny).
-export([x/0, y/0, z/0]).
x() ->
    lists:foldl(fun (E, A) -> some_mod:xyz(E, A) end, [], [1, 2, 3]).
y() ->
    some_mod:xyz(1, 2).
z() ->
    (fun(E, A) -> some_mod:xyz(E, A) end)(1, 2).
1> catch power_shell:eval(thingy, x, []).
{'EXIT',{undef,[{lists,foldl,
                       [#Fun<power_shell_eval.43.115918300>,[],[1,2,3]],
                       []},
                {lists,foldl,3,[]},
                {thingy,x,0,[]},
                {erl_eval,do_apply,6,[{file,"erl_eval.erl"},{line,689}]},
                {erl_eval,expr,5,[{file,"erl_eval.erl"},{line,434}]},
                {shell,exprs,7,[{file,"shell.erl"},{line,686}]},
                {shell,eval_exprs,7,[{file,"shell.erl"},{line,642}]},
                {shell,eval_loop,3,[{file,"shell.erl"},{line,627}]}]}}
2> catch power_shell:eval(thingy, y, []).
{'EXIT',{undef,[{some_mod,xyz,[1,2],[]},
                {thingy,y,0,[]},
                {erl_eval,do_apply,6,[{file,"erl_eval.erl"},{line,689}]},
                {erl_eval,expr,5,[{file,"erl_eval.erl"},{line,434}]},
                {shell,exprs,7,[{file,"shell.erl"},{line,686}]},
                {shell,eval_exprs,7,[{file,"shell.erl"},{line,642}]},
                {shell,eval_loop,3,[{file,"shell.erl"},{line,627}]}]}}
3> catch power_shell:eval(thingy, z, []).
{'EXIT',{undef,[{some_mod,xyz,[1,2],[]},
                {thingy,z,0,[]},
                {erl_eval,do_apply,6,[{file,"erl_eval.erl"},{line,689}]},
                {erl_eval,expr,5,[{file,"erl_eval.erl"},{line,434}]},
                {shell,exprs,7,[{file,"shell.erl"},{line,686}]},
                {shell,eval_exprs,7,[{file,"shell.erl"},{line,642}]},
                {shell,eval_loop,3,[{file,"shell.erl"},{line,627}]}]}}

potatosalad avatar Nov 29 '21 18:11 potatosalad