diff options
author | Björn Gustavsson <[email protected]> | 2014-02-06 10:08:01 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2014-02-06 10:08:01 +0100 |
commit | 3efa33db1e59b400babf672b07763c4a2467798a (patch) | |
tree | 6206771cfb14ab3a1072b3a802e464129ff9fa5d /lib/compiler/test | |
parent | dc85bc5a8ea9e3c6409e960aabb41ebb6fa47c1b (diff) | |
parent | 5d1471fae699fed9318ea6cad939156c2775d8be (diff) | |
download | otp-3efa33db1e59b400babf672b07763c4a2467798a.tar.gz otp-3efa33db1e59b400babf672b07763c4a2467798a.tar.bz2 otp-3efa33db1e59b400babf672b07763c4a2467798a.zip |
Merge branch 'bjorn/compiler/optimizations/OTP-11584'
* bjorn/compiler/optimizations/OTP-11584:
sys_core_fold: Prevent case expressions from being evaluated twice
sys_core_fold_SUITE: For cleanliness, move id/1 to the end
Diffstat (limited to 'lib/compiler/test')
-rw-r--r-- | lib/compiler/test/core_fold_SUITE.erl | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/lib/compiler/test/core_fold_SUITE.erl b/lib/compiler/test/core_fold_SUITE.erl index 69f61a046f..8151dc1b16 100644 --- a/lib/compiler/test/core_fold_SUITE.erl +++ b/lib/compiler/test/core_fold_SUITE.erl @@ -22,7 +22,8 @@ init_per_group/2,end_per_group/2, t_element/1,setelement/1,t_length/1,append/1,t_apply/1,bifs/1, eq/1,nested_call_in_case/1,guard_try_catch/1,coverage/1, - unused_multiple_values_error/1,unused_multiple_values/1]). + unused_multiple_values_error/1,unused_multiple_values/1, + multiple_aliases/1]). -export([foo/0,foo/1,foo/2,foo/3]). @@ -38,7 +39,8 @@ groups() -> [{p,test_lib:parallel(), [t_element,setelement,t_length,append,t_apply,bifs, eq,nested_call_in_case,guard_try_catch,coverage, - unused_multiple_values_error,unused_multiple_values]}]. + unused_multiple_values_error,unused_multiple_values, + multiple_aliases]}]. init_per_suite(Config) -> @@ -299,8 +301,6 @@ cover_is_safe_bool_expr(X) -> bsm_an_inlined(<<_:8>>, _) -> ok; bsm_an_inlined(_, _) -> error. -id(I) -> I. - unused_multiple_values_error(Config) when is_list(Config) -> PrivDir = ?config(priv_dir, Config), Dir = filename:dirname(code:which(?MODULE)), @@ -338,3 +338,31 @@ do_something(I) -> put(unused_multiple_values, [I|get(unused_multiple_values)]), I. + + +%% Make sure that multiple aliases does not cause +%% the case expression to be evaluated twice. +multiple_aliases(Config) when is_list(Config) -> + do_ma(fun() -> + X = Y = run_once(), + {X,Y} + end, {ok,ok}), + do_ma(fun() -> + case {true,run_once()} of + {true=A=B,ok=X=Y} -> + {A,B,X,Y} + end + end, {true,true,ok,ok}), + ok. + +do_ma(Fun, Expected) when is_function(Fun, 0) -> + Expected = Fun(), + ran_once = erase(run_once), + ok. + +run_once() -> + undefined = put(run_once, ran_once), + ok. + + +id(I) -> I. |