diff options
author | Björn Gustavsson <[email protected]> | 2016-05-09 08:18:02 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2016-05-12 14:52:07 +0200 |
commit | a0bef9607f44c273a1dcebd639af3bc68f2c9872 (patch) | |
tree | d9ed2dc79c1bacf3ba32d6f4e3b2107f6d82f296 | |
parent | 620ff5f6c52c34b874778025ae743c80f9d13f8e (diff) | |
download | otp-a0bef9607f44c273a1dcebd639af3bc68f2c9872.tar.gz otp-a0bef9607f44c273a1dcebd639af3bc68f2c9872.tar.bz2 otp-a0bef9607f44c273a1dcebd639af3bc68f2c9872.zip |
sys_core_fold: Don't generated failing calls such as 3(4)
Rewrite code such as:
X = not_a_fun,
X()
to:
error({badfun,not_a_fun})
Also generate a warning.
-rw-r--r-- | lib/compiler/src/sys_core_fold.erl | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/compiler/src/sys_core_fold.erl b/lib/compiler/src/sys_core_fold.erl index b5b8d8a8ec..dbc27db377 100644 --- a/lib/compiler/src/sys_core_fold.erl +++ b/lib/compiler/src/sys_core_fold.erl @@ -374,10 +374,21 @@ expr(#c_receive{clauses=Cs0,timeout=T0,action=A0}=Recv, Ctxt, Sub) -> T1 = expr(T0, value, Sub), A1 = body(A0, Ctxt, Sub), Recv#c_receive{clauses=Cs1,timeout=T1,action=A1}; -expr(#c_apply{op=Op0,args=As0}=App, _, Sub) -> +expr(#c_apply{anno=Anno,op=Op0,args=As0}=App, _, Sub) -> Op1 = expr(Op0, value, Sub), As1 = expr_list(As0, value, Sub), - App#c_apply{op=Op1,args=As1}; + case Op1 of + #c_var{} -> + App#c_apply{op=Op1,args=As1}; + _ -> + add_warning(App, invalid_call), + Err = #c_call{anno=Anno, + module=#c_literal{val=erlang}, + name=#c_literal{val=error}, + args=[#c_tuple{es=[#c_literal{val='badfun'}, + Op1]}]}, + make_effect_seq(As1++[Err], Sub) + end; expr(#c_call{module=M0,name=N0}=Call0, Ctxt, Sub) -> M1 = expr(M0, value, Sub), N1 = expr(N0, value, Sub), @@ -3395,6 +3406,8 @@ format_error({no_effect,{erlang,F,A}}) -> format_error(result_ignored) -> "the result of the expression is ignored " "(suppress the warning by assigning the expression to the _ variable)"; +format_error(invalid_call) -> + "invalid function call"; format_error(useless_building) -> "a term is constructed, but never used"; format_error(bin_opt_alias) -> |