1
%%%-------------------------------------------------------------------
2
%%% From : Fredrik Thulin <ft@it.su.se>
4
%%% A module with an erroneous record field declaration which mixes up
5
%%% structured and opaque terms and causes a crash in dialyzer.
7
%%% In addition, it revealed that the compiler produced extraneous
8
%%% warnings about unused record definitions when in fact they are
9
%%% needed for type declarations. This is now fixed.
10
%%%-------------------------------------------------------------------
13
-export([add/3, empty/0]).
15
%%--------------------------------------------------------------------
17
-record(sipurl, {proto = "sip" :: string(), host :: string()}).
18
-record(keylist, {list = [] :: [_]}).
19
-type sip_headers() :: #keylist{}.
20
-record(request, {uri :: #sipurl{}, header :: sip_headers()}).
21
-type sip_request() :: #request{}.
23
%%--------------------------------------------------------------------
25
-record(target, {branch :: string(), request :: sip_request()}).
26
-opaque target() :: #target{}.
28
-record(targetlist, {list :: target()}). % XXX: THIS ONE SHOULD READ [target()]
29
-opaque targetlist() :: #targetlist{}.
31
%%====================================================================
33
add(Branch, #request{} = Request, #targetlist{list = L} = TargetList) ->
34
case get_using_branch(Branch, TargetList) of
36
NewTarget = #target{branch = Branch, request = Request},
37
#targetlist{list = L ++ [NewTarget]};
42
-spec empty() -> targetlist().
45
#targetlist{list = []}.
47
get_using_branch(Branch, #targetlist{list = L}) when is_list(Branch) ->
48
get_using_branch2(Branch, L).
50
get_using_branch2(_Branch, []) ->
52
get_using_branch2(Branch, [#target{branch=Branch}=H | _T]) ->
54
get_using_branch2(Branch, [#target{} | T]) ->
55
get_using_branch2(Branch, T).