aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/test
diff options
context:
space:
mode:
authorJohn Högberg <[email protected]>2019-01-17 14:45:55 +0100
committerJohn Högberg <[email protected]>2019-01-21 07:51:06 +0100
commit53b46c186051e256a4238f4c4b75e3dcbf61a1b0 (patch)
treed6521712017053fe23fd07c19c257d4c64d144be /lib/compiler/test
parent2d96971a96868d70a750422788d1493a5cbed605 (diff)
downloadotp-53b46c186051e256a4238f4c4b75e3dcbf61a1b0.tar.gz
otp-53b46c186051e256a4238f4c4b75e3dcbf61a1b0.tar.bz2
otp-53b46c186051e256a4238f4c4b75e3dcbf61a1b0.zip
beam_ssa_type: Fix type subtraction in #b_switch{}
A switch is equivalent to a series of '=:=', so we have to subtract each value individually from the type. Subtracting a join risks removing too much type information, and managed to narrow "number" into "float" in the attached test case.
Diffstat (limited to 'lib/compiler/test')
-rw-r--r--lib/compiler/test/float_SUITE.erl15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/compiler/test/float_SUITE.erl b/lib/compiler/test/float_SUITE.erl
index 012810aba2..831e8279aa 100644
--- a/lib/compiler/test/float_SUITE.erl
+++ b/lib/compiler/test/float_SUITE.erl
@@ -20,7 +20,8 @@
-module(float_SUITE).
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
init_per_group/2,end_per_group/2,
- pending/1,bif_calls/1,math_functions/1,mixed_float_and_int/1]).
+ pending/1,bif_calls/1,math_functions/1,mixed_float_and_int/1,
+ subtract_number_type/1]).
-include_lib("common_test/include/ct.hrl").
@@ -28,7 +29,7 @@ suite() -> [{ct_hooks,[ts_install_cth]}].
all() ->
[pending, bif_calls, math_functions,
- mixed_float_and_int].
+ mixed_float_and_int, subtract_number_type].
groups() ->
[].
@@ -176,5 +177,15 @@ mixed_float_and_int(Config) when is_list(Config) ->
pc(Cov, NotCov, X) ->
round(Cov/(Cov+NotCov)*100) + 42 + 2.0*X.
+subtract_number_type(Config) when is_list(Config) ->
+ 120 = fact(5).
+
+fact(N) ->
+ fact(N, 1).
+
+fact(0, P) -> P;
+fact(1, P) -> P;
+fact(N, P) -> fact(N-1, P*N).
+
id(I) -> I.