diff --git a/lib/compiler/src/beam_ssa_type.erl b/lib/compiler/src/beam_ssa_type.erl index b40fedcac76a..9b4db8998361 100644 --- a/lib/compiler/src/beam_ssa_type.erl +++ b/lib/compiler/src/beam_ssa_type.erl @@ -329,7 +329,7 @@ sig_fun_call(I0, Args, Ts, Ds, Fdb, Sub, State0) -> CallArgs = CallArgs0 ++ simplify_args(Env, Ts, Sub), I = I0#b_set{args=[Callee | CallArgs]}, sig_local_call(I, Callee, CallArgs, Ts, Fdb, State0); - {#t_fun{target={Name,Arity}}, _} -> + {#t_fun{arity=Arity,target={Name,Arity}}, _} -> %% When a fun lacks free variables, we can make a direct call even %% when we don't know where it was defined. Callee = #b_local{name=#b_literal{val=Name}, @@ -683,7 +683,7 @@ opt_fun_call(#b_set{dst=Dst}=I0, [Fun | CallArgs0], Ts, Ds, Fdb, Sub, Meta) -> CallArgs = CallArgs0 ++ simplify_args(Env, Ts, Sub), I = I0#b_set{args=[Callee | CallArgs]}, opt_local_call(I, Callee, CallArgs, Dst, Ts, Fdb, Meta); - {#t_fun{target={Name,Arity}}, _} -> + {#t_fun{arity=Arity,target={Name,Arity}}, _} -> %% When a fun lacks free variables, we can make a direct call even %% when we don't know where it was defined. Callee = #b_local{name=#b_literal{val=Name}, diff --git a/lib/compiler/test/fun_SUITE.erl b/lib/compiler/test/fun_SUITE.erl index 0d5936824ae8..e5365b5fa14e 100644 --- a/lib/compiler/test/fun_SUITE.erl +++ b/lib/compiler/test/fun_SUITE.erl @@ -24,7 +24,7 @@ test1/1,overwritten_fun/1,otp_7202/1,bif_fun/1, external/1,eep37/1,badarity/1,badfun/1, duplicated_fun/1,unused_fun/1,parallel_scopes/1, - coverage/1]). + coverage/1,leaky_environment/1]). %% Internal exports. -export([call_me/1,dup1/0,dup2/0]). @@ -41,7 +41,7 @@ groups() -> [test1,overwritten_fun,otp_7202,bif_fun,external,eep37, badarity,badfun,duplicated_fun,unused_fun, parallel_scopes, - coverage]}]. + coverage,leaky_environment]}]. init_per_suite(Config) -> test_lib:recompile(?MODULE), @@ -590,5 +590,11 @@ coverage_2(List) -> coverage_3({[], A}) -> {id(42), fun() -> A end}. +leaky_environment(_Config) -> + G = fun(X, Y) -> X + Y end, + F = fun(A) -> G(A, 0) end, + {'EXIT', {{badarity, {F, [1, flurb]}}, _}} = catch F(1, flurb), + ok. + id(I) -> I.