aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/v3_core.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2019-05-09 13:22:24 +0200
committerBjörn Gustavsson <[email protected]>2019-05-14 16:11:55 +0200
commit119e72d3e766089dc7347b75d0530b0c626cff93 (patch)
tree7fa969e90ee393d54fb641747312ea516b9929bd /lib/compiler/src/v3_core.erl
parent7611d65a46ce2a811890085f166799701f6bba2b (diff)
downloadotp-119e72d3e766089dc7347b75d0530b0c626cff93.tar.gz
otp-119e72d3e766089dc7347b75d0530b0c626cff93.tar.bz2
otp-119e72d3e766089dc7347b75d0530b0c626cff93.zip
Fix compiler crash when funs were matched
Code such as the following would crash the compiler in OTP 22: [some_atom = fun some_function/1] The reason is that the fun would be copied (used both in the match operation and as a value in the list), and the copy of the fun would create two wrapper functions with the same name for calling some_function/1. In OTP 21, the duplicate functions happened not to cause any harm (one of the wrappers functions would be unused and ultimately be removed by beam_clean). In OTP 22, the new beam_ssa_type pass would be confused by the multiple definitions of the wrapper function.
Diffstat (limited to 'lib/compiler/src/v3_core.erl')
-rw-r--r--lib/compiler/src/v3_core.erl3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/compiler/src/v3_core.erl b/lib/compiler/src/v3_core.erl
index 3699c9d22e..007a0247f4 100644
--- a/lib/compiler/src/v3_core.erl
+++ b/lib/compiler/src/v3_core.erl
@@ -1811,7 +1811,8 @@ force_safe(Ce, St0) ->
is_safe(#c_cons{}) -> true;
is_safe(#c_tuple{}) -> true;
-is_safe(#c_var{}) -> true;
+is_safe(#c_var{name={_,_}}) -> false; %Fun. Not safe.
+is_safe(#c_var{name=_}) -> true; %Ordinary variable.
is_safe(#c_literal{}) -> true;
is_safe(_) -> false.