aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dialyzer/test/indent_SUITE_data/src/callbacks_and_specs/my_callbacks_wrong.erl
blob: 0459622dc11a2fe8343a0a4f41d431d3bac349a5 (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
-module(my_callbacks_wrong).

-export([
	 callback_init/1
	 , callback_call/3
	 , callback_cast/3
	 , callback_exit/1
	]).

-behaviour(my_behaviour).

-record(state, {
	  parent           :: pid(),
	  status    = init :: 'init' | 'open' | 'closed',
	  subscribe = []   :: list({pid(), integer()}),
	  counter   = 1    :: integer()
	 }).

-type state()        :: #state{}.

-type cast_message() :: 'open' | 'closed'.

-type call_message() :: 'subscribe' | 'unsubscribe'.
-type call_reply()   :: 'accepted' | 'rejected'.

-spec callback_init(Parent::pid()) -> state().    %% Wrong return spec

callback_init(Parent) -> #state{parent = Parent}. %% Wrong return

-spec callback_cast(state(), pid() | atom(), cast_message()) ->
			   {'noreply' | 'reply', state()}. %% More generic spec

callback_cast(#state{parent = Pid} = State, Pid, Message)
  when Message =:= 'open'; Message =:= 'close' ->
    {noreply, State#state{status = Message}};
callback_cast(State, _Pid, _Message) ->
    {noreply, State}.

-spec callback_call(state(), atom(), call_message()) ->      %% Wrong arg spec
			   {'reply', state(), call_reply()}.

callback_call(#state{status = open, subscribe = Subscribers} = State,
	      Pid, Message)
  when Message =:= 'subscribe';
       Message =:= 'unsubscribe' ->
    NewState =
	case Message of
	    subscribe ->
		N = State#state.counter,
		State#state{subscribe = [{Pid, N}|Subscribers], counter = N+1};
	    unsubscribe ->
		State#state{subscribe = lists:keydelete(Pid, 1, Subscribers)}
	end,
    {reply, NewState, accepted};
callback_call(State, _Pid, _Message) ->
    {reply, State, rejected}.

-spec callback_exit(state()) -> ok.

callback_exit(_State) ->
    ok.