@@ -275,11 +275,22 @@ State = R6Class("State",
275275 # ' @param next_step (State or Chain): Next state or chain to transition to.
276276 # ' @return State or Chain: Next state or chain that will be transitioned to.
277277 .next = function (next_step ){
278- if (self $ type %in% c(' Choice ' , ' Succeed' , ' Fail' ))
278+ if (self $ type %in% c(' Succeed' , ' Fail' ))
279279 stop(sprintf(
280280 ' Unexpected State instance `%s`, State type `%s` does not support method `next`.' ,
281281 next_step , self $ type ))
282282
283+ # By design, Choice states do not have the Next field. When used in a chain, the subsequent step becomes the
284+ # default choice that executes if none of the specified rules match.
285+ # See language spec for more info: https://states-language.net/spec.html#choice-state
286+ if (self $ type == ' Choice' ){
287+ if (is.null(self $ default ))
288+ LOGGER $ warning(
289+ " Chaining Choice state: Overwriting %s's current default_choice (%s) with %s" ,
290+ self $ state_id , self $ default $ state_id , next_step $ state_id )
291+ self $ default_choice(next_step )
292+ return (self $ default )
293+ }
283294 self $ next_step = next_step
284295 return (self $ next_step )
285296 },
@@ -555,7 +566,8 @@ Wait = R6Class("Wait",
555566# ' pattern-matches against the rules in list order and transitions to the
556567# ' state or chain specified in the *next_step* field on the first *rule* where
557568# ' there is an exact match between the input value and a member of the
558- # ' comparison-operator array.
569+ # ' comparison-operator array. When used in a chain, the subsequent step
570+ # ' becomes the default choice that executes if none of the specified rules match.
559571# ' @export
560572Choice = R6Class(" Choice" ,
561573 inherit = State ,
0 commit comments