diff options
author | Raimo Niskanen <[email protected]> | 2016-02-26 10:51:53 +0100 |
---|---|---|
committer | Raimo Niskanen <[email protected]> | 2016-02-26 10:51:53 +0100 |
commit | efda33e83f2bbc666f6ec261d54ad95c38acbc36 (patch) | |
tree | 31836a3a418b0d97082d040edd06e95209cda1f5 /lib/stdlib | |
parent | 1e4831762b5ab4bd2210fc9e0a204e00dfe81b39 (diff) | |
download | otp-efda33e83f2bbc666f6ec261d54ad95c38acbc36.tar.gz otp-efda33e83f2bbc666f6ec261d54ad95c38acbc36.tar.bz2 otp-efda33e83f2bbc666f6ec261d54ad95c38acbc36.zip |
Allow actions without containing list
Type check atom state as early as possible
Diffstat (limited to 'lib/stdlib')
-rw-r--r-- | lib/stdlib/src/gen_statem.erl | 21 | ||||
-rw-r--r-- | lib/stdlib/test/gen_statem_SUITE.erl | 6 |
2 files changed, 19 insertions, 8 deletions
diff --git a/lib/stdlib/src/gen_statem.erl b/lib/stdlib/src/gen_statem.erl index 16c296794f..83de4114a7 100644 --- a/lib/stdlib/src/gen_statem.erl +++ b/lib/stdlib/src/gen_statem.erl @@ -571,7 +571,9 @@ init_result(Starter, Parent, ServerRef, Module, Result, Opts) -> case Result of {CallbackMode,State,Data} -> case callback_mode(CallbackMode) of - true -> + true + when CallbackMode =:= state_functions, is_atom(State); + CallbackMode =/= state_functions -> proc_lib:init_ack(Starter, {ok,self()}), enter( Module, Opts, CallbackMode, State, Data, @@ -840,7 +842,7 @@ loop_events( %% Interpret all callback return value variants loop_event_result( Parent, Debug, - #{state := State, data := Data} = S, + #{callback_mode := CallbackMode, state := State, data := Data} = S, Events, Event, Result) -> case Result of stop -> @@ -866,12 +868,15 @@ loop_event_result( exit, Reason, ?STACKTRACE(), Debug, NewS, Q, Replies), %% Since we got back here Replies was bad terminate(Class, NewReason, Stacktrace, NewDebug, NewS, Q); - {next_state,NewState,NewData} -> + {next_state,NewState,NewData} + when CallbackMode =:= state_functions, is_atom(NewState); + CallbackMode =/= state_functions -> loop_event_actions( Parent, Debug, S, Events, Event, State, NewState, NewData, []); {next_state,NewState,NewData,Actions} - when is_list(Actions) -> + when CallbackMode =:= state_functions, is_atom(NewState); + CallbackMode =/= state_functions -> loop_event_actions( Parent, Debug, S, Events, Event, State, NewState, NewData, Actions); @@ -900,7 +905,13 @@ loop_event_actions( Parent, Debug, S, Events, Event, State, NewState, NewData, Actions) -> loop_event_actions( Parent, Debug, S, Events, Event, State, NewState, NewData, - false, false, undefined, [], Actions). + false, false, undefined, [], + if + is_list(Actions) -> + Actions; + true -> + [Actions] + end). %% loop_event_actions( Parent, Debug, #{postponed := P0} = S, Events, Event, diff --git a/lib/stdlib/test/gen_statem_SUITE.erl b/lib/stdlib/test/gen_statem_SUITE.erl index 09b309c36f..0429c0e5f4 100644 --- a/lib/stdlib/test/gen_statem_SUITE.erl +++ b/lib/stdlib/test/gen_statem_SUITE.erl @@ -1178,7 +1178,7 @@ idle({call,From}, {delayed_answer,T}, Data) -> end; idle({call,From}, {timeout,Time}, _Data) -> {next_state,timeout,{From,Time}, - [{timeout,Time,idle}]}; + {timeout,Time,idle}}; idle(Type, Content, Data) -> case handle_common_events(Type, Content, idle, Data) of undefined -> @@ -1220,7 +1220,7 @@ timeout3(_, _, Data) -> wfor_conf({call,From}, confirm, Data) -> {next_state,connected,Data, - [{reply,From,yes}]}; + {reply,From,yes}}; wfor_conf(cast, {ping,_,_}, _) -> {keep_state_and_data,[postpone]}; wfor_conf(cast, confirm, Data) -> @@ -1241,7 +1241,7 @@ wfor_conf(Type, Content, Data) -> connected({call,From}, {msg,Ref}, Data) -> {keep_state,Data, - [{reply,From,{ack,Ref}}]}; + {reply,From,{ack,Ref}}}; connected(cast, {msg,From,Ref}, Data) -> From ! {ack,Ref}, {keep_state,Data}; |