From f59e70ce61913356a67d58e03d6b68c29e983363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 7 Aug 2017 07:00:14 +0200 Subject: sys_core_fold: Fix unsafe optimization of non-variable apply The sys_core_fold pass would do an unsafe "optimization" when an apply operation did not have a variable in the function position as in the following example: > cat test1.core module 'test1' ['test1'/2] attributes [] 'i'/1 = fun (_f) -> _f 'test1'/2 = fun (_f, _x) -> apply apply 'i'/1 (_f) (_x) end > erlc test1.core no_file: Warning: invalid function call Reported-by: Mikael Pettersson --- lib/compiler/src/sys_core_fold.erl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/compiler/src/sys_core_fold.erl') diff --git a/lib/compiler/src/sys_core_fold.erl b/lib/compiler/src/sys_core_fold.erl index e0cd6da06f..d73060fb7e 100644 --- a/lib/compiler/src/sys_core_fold.erl +++ b/lib/compiler/src/sys_core_fold.erl @@ -395,10 +395,10 @@ expr(#c_receive{clauses=Cs0,timeout=T0,action=A0}=Recv, Ctxt, Sub) -> expr(#c_apply{anno=Anno,op=Op0,args=As0}=App, _, Sub) -> Op1 = expr(Op0, value, Sub), As1 = expr_list(As0, value, Sub), - case Op1 of - #c_var{} -> + case cerl:is_data(Op1) of + false -> App#c_apply{op=Op1,args=As1}; - _ -> + true -> add_warning(App, invalid_call), Err = #c_call{anno=Anno, module=#c_literal{val=erlang}, -- cgit v1.2.3