aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/test/opaque_SUITE_data/src/simple/rec_api.erl
blob: d9b1d59f0cac29f9f75c9f8ba13666ee7b665245 (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
-module(rec_api).

-export([t1/0, t2/0, adt_t1/0, adt_t1/1, adt_r1/0,
         t/1, t_adt/0, r/0, r_adt/0]).

-export_type([{a,0},{r1,0}]).

-export_type([f/0, op_t/0, r/0, tup/0]).

-opaque a() :: a | b.

-record(r1,
        {f1 :: a()}).

-opaque r1() :: #r1{}.

t1() ->
    A = #r1{f1 = a},
    {r1, a} = A.

t2() ->
    A = {r1, 10}, % violates the type of #r1{}
    {r1, 10} = A. % violates the type of #r1{}

adt_t1() ->
    R = rec_adt:r1(),
    {r1, a} = R. % breaks the opaqueness

-spec adt_t1(rec_adt:r1()) -> rec_adt:r1(). % invalid type spec

adt_t1(R) ->
    {r1, a} = R.

-spec adt_r1() -> rec_adt:r1(). % invalid type spec

adt_r1() ->
    #r1{f1 = a}.

-opaque f() :: fun((_) -> _).

-opaque op_t() :: integer().

-spec t(f()) -> _.

t(A) ->
    T = term(),
    %% 3(T), % cannot test this: dialyzer_dep deliberately crashes
    A(T).

-spec term() -> op_t().

term() ->
    3.

t_adt() ->
    A = rec_adt:f(),
    T = term(),
    A(T).

-record(r, {f = fun(_) -> 3 end :: f(), o = 1 :: op_t()}).

-opaque r() :: #r{}.

-opaque tup() :: {'r', f(), op_t()}.

-spec r() -> _.

r() ->
    {r, f(), 2}. % OK, f() is a local opaque type

-spec f() -> f().

f() ->
    fun(_) -> 3 end.

r_adt() ->
    {r, rec_adt:f(), 2}. % breaks the opaqueness