Transitions to nested states do not work as expected

0 votes
asked Jan 30 in Bug by nsk

Hi! I have the following state-diagram.

I meet an unexpected behavior when I declare transitions to nested states of a neighbor state.

In this diagram state 22 is rendering as a child of state 1 but I expect it to be a child of state 2.

This works as expected if I move transition 11 --> 22 to any place after state 22 declaration.

The second point is that if I declare similar transition but with top level state as a target (state 2) it works as expected. 

Is that expected behavior, and if so what is the good way to declare such transitions?

@startuml
hide empty description

state 1 {
    state 11 : I am a child of 1
    
    [*] --> 11
    11 --> 22 : this transition does not work as expected
    11 --> 2 : but this works
}
state 2 {
    state 21 : I am a child of 2
    state 22 : I am a child of 2
    
    [*] --> 21
}

[*] --> 1
@enduml

1 Answer

0 votes
answered Jan 30 by albert (3,120 points)

It looks like this is a bit of an order / moment of definition problem.

A possible solution might be:

@startuml
hide empty description

state 1 {
    state 11 : I am a child of 1
    
    [*] --> 11
    
    11 --> 2 : but this works
}

state 2 {
    state 21 : I am a child of 2
    state 22 : I am a child of 2
    
    [*] --> 21
}
11 --> 22 : this transition does not work as expected
[*] --> 1
@enduml

See also for the image: http://www.plantuml.com/plantuml/uml/RP31gi8m44Nt-OgxVj35PFaMZsxVDuYBs8mqs2ObCqL5_7TZg5Ancq26CvnxfnLrMUTnC7tm31udlSApT3bC6b8qfW3A8DmC02m_mY_-uKOuT7qOFD8HL87wx7xsQ9e_q6f6L4UsR1vcXVP1S4xv9ER-ajWFYTsIs3LWju3l59QAOj7NdUhMxAA4PqVun8AOjEQ14_1buaxPctSHqtBqvKmF

In other words move the 11 --> 22 outside of state 1 and show it after state 2 has been filled

commented Jan 30 by nsk
Yes I know this solution, but I thought that maybe there is a better way.

Thank you.
...