aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/test/unmatched_returns_SUITE_data/src/lc_warnings/lc_warnings.erl
blob: cb01a8fde3dee4b9fe9cb9f8c490fce1ae359bc0 (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
89
90
91
92
93
94
95
-module(lc_warnings).
-compile([export_all]).

close(Fs) ->
    %% There should be a warning since we ignore a potential
    %% {error,Error} return from file:close/1.
    [file:close(F) || F <- Fs],

    %% No warning because the type of unmatched return will be ['ok']
    %% (which is a list of a simple type).
    [ok = file:close(F) || F <- Fs],

    %% Suppressed.
    _ = [file:close(F) || F <- Fs],
    ok.

format(X) ->
    %% No warning since the result of the list comprehension is
    %% a list of simple.
    [io:format("~p\n", [E]) || E <- X],

    %% Warning explicitly suppressed.
    _ = [io:format("~p\n", [E]) || E <- X],
    ok.

opaque1() ->
    List = gen_atom(),
    %% This is a list of an externally defined opaque type. Since
    %% we are not allowed to peek inside opaque types, there should
    %% be a warning (even though the type in this case happens to be
    %% an atom).
    [E || E <- List],

    %% Suppressed.
    _ = [E || E <- List],
    ok.

opaque2() ->
    List = gen_array(),
    %% This is an list of an externally defined opaque type. Since
    %% we are not allowed to peek inside opaque types, there should
    %% be a warning.
    [E || E <- List],

    %% Suppressed.
    _ = [E || E <- List],
    ok.

opaque3() ->
    List = gen_int(),

    %% No warning, since we are allowed to look into the type and can
    %% see that it is a simple type.
    [E || E <- List],

    %% Suppressed.
    _ = [E || E <- List],
    ok.

opaque4() ->
    List = gen_tuple(),

    %% There should be a warning, since we are allowed to look inside
    %% the opaque type and see that it is a tuple (non-simple).
    [E || E <- List],

    %% Suppressed.
    _ = [E || E <- List],
    ok.

gen_atom() ->
    [opaque_atom_adt:atom(ok)].

gen_array() ->
    [array:new()].


gen_int() ->
    [opaque_int(42)].

gen_tuple() ->
    [opaque_tuple(x, 25)].

-opaque opaque_int() :: integer().

-spec opaque_int(integer()) -> opaque_int().

opaque_int(Int) -> Int.

-opaque opaque_tuple() :: {any(),any()}.

-spec opaque_tuple(any(), any()) -> opaque_tuple().

opaque_tuple(X, Y) ->
    {X,Y}.