diff options
-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}; |