aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/test/map_SUITE_data/src/typeflow2.erl
blob: 71a9657a6072d667b4a7992b344eb034ba5ea47f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
-module(typeflow2).

-export([t1/1, t2/1, t3/1, t4/1, t5/1, t6/1, t7/1, optional3/1]).

t1(L) ->
    M = only_integers_and_lists(L),
    optional(M),
    case M of
	#{a := X} when is_integer(X) -> ok;
	#{a := X} when is_list(X) -> ok; %% Must warn here
	#{a := X} when is_pid(X) -> ok;
	_ -> fail
    end.

optional(#{a:=X}) ->
    true = is_integer(X);
optional(#{}) ->
    true.

only_integers_and_lists(L) -> only_integers_and_lists(L, #{}).

only_integers_and_lists([], M) -> M;
only_integers_and_lists([{K,V}|T], M) when is_integer(V); is_list(V)->
    only_integers_and_lists(T, M#{K => V}).

t2(L) ->
    M = only_integers_and_lists(L),
    optional(M),
    lists:sort(maps:get(a, M)),
    ok.

t3(L) ->
    M = only_integers_and_lists(L),
    lists:sort(maps:get(a, M)),
    ok.

t4(V) ->
    M=map_with(a,V),
    optional2(M),
    case M of
	#{a := X} when is_integer(X) -> ok;
	#{a := X} when is_list(X) -> ok; %% Must warn here
	_ -> fail
    end.

optional2(#{a:=X}) ->
    true = is_integer(X);
optional2(#{}) ->
    true.

map_with(K, V) when is_integer(V); is_list(V); is_atom(V) -> #{K => V}.

t5(L) ->
    M = only_integers_and_lists(L),
    optional3(M),
    case M of
	#{a := X} when is_integer(X) -> ok;
	#{a := X} when is_list(X) -> ok; %% Must warn here
	#{a := X} when is_pid(X) -> ok; %% Must warn here
	#{a := X} when is_atom(X) -> ok;
	_ -> fail
    end.

t6(L) ->
    M = only_integers_and_lists(L),
    case M of
	#{a := X} when is_integer(X) -> ok;
	#{a := X} when is_list(X) -> ok; %% Must not warn here
	_ -> fail
    end.

optional3(#{a:=X}) ->
    true = is_integer(X);
optional3(#{}) ->
    true.

t7(M) ->
    optional4(M),
    case M of
	#{a := X} when is_integer(X) -> ok;
	#{a := X} when is_list(X) -> ok;
	#{a := X} when is_pid(X) -> ok; %% Must warn here
	#{a := X} when is_atom(X) -> ok; %% Must warn here
	_ -> fail %% Must not warn here (requires parsing)
    end.

-spec optional4(#{a=>integer()|list()}) -> true.
optional4(#{}) -> true.