Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anonymous transition in a nested state are not being executed unless on_entry event is declared in transition table #626

Open
deoliveiravinicius opened this issue Aug 19, 2024 · 0 comments

Comments

@deoliveiravinicius
Copy link

deoliveiravinicius commented Aug 19, 2024

Anonymous transitions in a nested state are not being executed unless on_entry event is declared in transition table.

The following test, which is a slightly modified version of this line 112, fails if we remove on_entry action in the sub_sm

test subsequent_anonymous_transitions_composite = [] {
  using V = std::string;
  V calls{};

  using namespace sml;

  struct sub_sub_sm {
    auto operator()() noexcept {
      // clang-format off
      return make_transition_table(
       *idle / [] (V& v) { v+="ss1|"; } = s1
       ,s1 / [] (V& v) { v+="ss2|"; } = s2
       ,s2 / [] (V& v) { v+="ss3|"; } = X
      );
      // clang-format on
    }
  };
  struct sub_sm {
    auto operator()() noexcept {
      // clang-format off
      return make_transition_table(
       *idle / [] (V& v) { v+="s1|"; } = s1
       ,s1 / [] (V& v) { v+="s2|"; } = s2
       ,s2 / [] (V& v) { v+="s3|"; } = state<sub_sub_sm>
       ,state<sub_sub_sm> / [] (V& v) { v+="s4|"; } = X
      // ,state<sub_sub_sm> + sml::on_entry<_>/[]{}   // REMOVING THIS LINE CAUSES THE ANONYMOUS TRANSITIONS IN THE NESTED STATE MACHINE TO NOT EXECUTE
      );
      // clang-format on
    }
  };

  struct composite_sm {
    auto operator()() noexcept {
      // clang-format off
      return make_transition_table(
       *idle / [] (V& v) { v+="11|"; } = s1
       ,s1 / [] (V& v) { v+="12|"; } = state<sub_sm>
       ,state<sub_sm> / [] (V& v) { v+="13|"; } = s2
       ,s2 / [] (V& v) { v+="14|"; } = s3
      );
      // clang-format on
    }
  };
  sml::sm<composite_sm> sm{calls};
  expect(sm.is<decltype(state<sub_sm>)>(X));
  expect(sm.is(s3));
    std::string expected("11|12|s1|s2|s3|ss1|ss2|ss3|s4|13|14|");
  expect(calls == expected);  
  std::cout << "call order: " << calls << std::endl;
};

Test output:

result:
call order: 11|12|

expected:
call order: 11|12|s1|s2|s3|ss1|ss2|ss3|s4|13|14|

Specifications

  • Version: 1.1.11
  • Platform: Ubuntu 22.04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant