1-module(lc_warnings).
2-compile([export_all]).
3
4close(Fs) ->
5    %% There should be a warning since we ignore a potential
6    %% {error,Error} return from file:close/1.
7    [file:close(F) || F <- Fs],
8
9    %% No warning because the type of unmatched return will be ['ok']
10    %% (which is a list of a simple type).
11    [ok = file:close(F) || F <- Fs],
12
13    %% Suppressed.
14    _ = [file:close(F) || F <- Fs],
15    ok.
16
17format(X) ->
18    %% No warning since the result of the list comprehension is
19    %% a list of simple.
20    [io:format("~p\n", [E]) || E <- X],
21
22    %% Warning explicitly suppressed.
23    _ = [io:format("~p\n", [E]) || E <- X],
24    ok.
25
26opaque1() ->
27    List = gen_atom(),
28    %% This is a list of an externally defined opaque type. Since
29    %% we are not allowed to peek inside opaque types, there should
30    %% be a warning (even though the type in this case happens to be
31    %% an atom).
32    [E || E <- List],
33
34    %% Suppressed.
35    _ = [E || E <- List],
36    ok.
37
38opaque2() ->
39    List = gen_array(),
40    %% This is an list of an externally defined opaque type. Since
41    %% we are not allowed to peek inside opaque types, there should
42    %% be a warning.
43    [E || E <- List],
44
45    %% Suppressed.
46    _ = [E || E <- List],
47    ok.
48
49opaque3() ->
50    List = gen_int(),
51
52    %% No warning, since we are allowed to look into the type and can
53    %% see that it is a simple type.
54    [E || E <- List],
55
56    %% Suppressed.
57    _ = [E || E <- List],
58    ok.
59
60opaque4() ->
61    List = gen_tuple(),
62
63    %% There should be a warning, since we are allowed to look inside
64    %% the opaque type and see that it is a tuple (non-simple).
65    [E || E <- List],
66
67    %% Suppressed.
68    _ = [E || E <- List],
69    ok.
70
71gen_atom() ->
72    [opaque_atom_adt:atom(ok)].
73
74gen_array() ->
75    [array:new()].
76
77
78gen_int() ->
79    [opaque_int(42)].
80
81gen_tuple() ->
82    [opaque_tuple(x, 25)].
83
84-opaque opaque_int() :: integer().
85
86-spec opaque_int(integer()) -> opaque_int().
87
88opaque_int(Int) -> Int.
89
90-opaque opaque_tuple() :: {any(),any()}.
91
92-spec opaque_tuple(any(), any()) -> opaque_tuple().
93
94opaque_tuple(X, Y) ->
95    {X,Y}.
96