1-module(union_adt).
2-export([new/1, new_a/1, new_rec/1]).
3
4%% Now (R17) that opaque types are no longer recognized by their shape
5%% this test case is rather meaningless.
6
7-record(rec, {x = 42 :: integer()}).
8
9-opaque u() :: 'aaa' | 'bbb' | #rec{}.
10
11-spec new(_) -> u().
12
13new(a) -> aaa;
14new(b) -> bbb;
15new(X) when is_integer(X) ->
16  #rec{x = X}.
17
18%% the following two functions (and their uses in union_use.erl) test
19%% that the return type is the opaque one and not just a subtype of it
20
21-spec new_a(_) -> u().
22
23new_a(a) -> aaa.
24
25-spec new_rec(_) -> u().
26
27new_rec(X) when is_integer(X) ->
28  #rec{x = X}.
29