Skip to content

Commit cd9603f

Browse files
committed
Adjust tests of unions with any() member
1 parent c594241 commit cd9603f

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

test/should_fail/union_with_any.erl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
%% T | any() means
44
%% "at least values of type T are possible; maybe also other values"
55

6-
-export([f1/1, f2/0, f3/1]).
6+
-export([f2/0, f3/1]).
77

8-
%% With spec
9-
-spec f1(atom() | any()) -> any().
10-
f1(X) -> inc(X).
8+
-gradualizer([infer]).
119

1210
%% Without spec
1311
f2() ->
1412
AtomOrAny = receive
15-
1 -> get_atom();
16-
Any -> Any
13+
1 -> get_atom();
14+
an_atom -> an_atom
1715
end,
1816
inc(AtomOrAny). %% Fails because atom() is possible
1917

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-module(union_with_any_pass).
2+
3+
-export([f1/1, f2/0]).
4+
5+
%% With spec
6+
-spec f1(atom() | any()) -> any().
7+
f1(X) -> inc(X).
8+
9+
%% Without spec
10+
f2() ->
11+
AtomOrAny = receive
12+
1 -> get_atom();
13+
Any -> Any
14+
end,
15+
inc(AtomOrAny). %% Fails because atom() is possible
16+
17+
-spec get_atom() -> atom().
18+
get_atom() -> banana.
19+
20+
-spec inc(number()) -> number().
21+
inc(N) -> N + 1.

test/should_pass_SUITE.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ all_tests() ->
100100
tuple_union_pass,tuple_union_pat,tuple_union_pattern_pass,type_decl,
101101
type_pattern,type_refinement_pass,type_variable,type_vars_term,
102102
typed_record_field_access,unary_negate_union_with_user_type_pass,unary_plus,
103-
underscore,user_type_in_pattern_body,user_types,var,var_fun,varbind_in_block,
104-
varbind_in_case,varbind_in_function_head,varbind_in_lc,variable_binding,
105-
variable_binding_leaks].
103+
underscore,union_with_any_pass,user_type_in_pattern_body,user_types,var,
104+
var_fun,varbind_in_block,varbind_in_case,varbind_in_function_head,
105+
varbind_in_lc,variable_binding,variable_binding_leaks].
106106

107107
should_pass_template(_@File) ->
108108
?assertEqual(ok, gradualizer:type_check_file(_@File, [{form_check_timeout_ms, 2000}])).

0 commit comments

Comments
 (0)