Detect Modeling Errors During Edit Time

When edit-time checking is enabled, the Stateflow® Editor detects potential errors and warnings as you work on your chart. By fixing these issues early in the design process, you can avoid compile-time or run-time warnings and errors.

The Stateflow editor highlights objects that violate the edit-time checks in red (for errors) or orange (for warnings). When you point to an object that is highlighted and click the error or warning badge, a tooltip displays details and possible fixes.

Manage Edit-Time Checks

By default, edit-time checking and syntax error highlighting are enabled. To disable the edit-time checks, in the Debug tab, clear the Diagnostics > Edit-Time Errors & Warnings check box.

This table lists edit-time checks that have an associated diagnostic configuration parameter on the Diagnostics > Stateflow pane of the Configuration Parameters dialog box.

You can control the level of diagnostic action for these edit-time checks by setting the value of their configuration parameter to error, warning, or none. When you change the setting for a configuration parameter, the diagnostic level for the corresponding edit-time checks also changes. For example, if you set the Unreachable execution path configuration parameter to none, then the Stateflow Editor does not highlight dangling transitions, transition shadowing, or unreachable states.

Dangling Transition

Every transition must have a valid destination state or junction. To resolve this issue, connect the transition to a state or junction. For more information, see Transitions.

Diagnostic configuration parameter: Unreachable execution path (Simulink)

Default Transition Is Missing

In a chart or state with exclusive (OR) decomposition and at least two substates or junctions, a default transition is required to indicate where the execution begins. To resolve this issue, specify an initial state by adding a default transition. For more information, see Default Transitions.

Diagnostic level: Error

Default Transition Path Does Not Terminate in a State

In charts or states with exclusive (OR) decomposition and at least one substate:

  • Every path along the default transition must lead to a substate.

  • There must be one default transition path that is not guarded by a condition or triggered by an event.

For more information, see Default Transitions.

Diagnostic configuration parameter: No unconditional default transitions (Simulink)

Graphical Function Contains a State

Because graphical functions execute completely in a single time step, they must not contain any states. To resolve this issue, replace the states with junctions. For more information, see Reuse Logic Patterns by Defining Graphical Functions.

Diagnostic level: Error

Invalid Default Transition Path

A default transition path must not exit the parent state. To resolve this issue, modify the default transition path so it stays within the parent state. For more information, see Default Transitions.

Diagnostic level: Error

Invalid History Junction

A history junction records the activity of substates in a superstate. A history junction is invalid when:

  • The history junction is contained in the chart level of the hierarchy.

  • The history junction is contained in a state with parallel (AND) decomposition.

  • The history junction is contained inside a graphical function.

  • The history junction is the source of a transition.

  • There are multiple history junctions contained in the same state.

For more information, see Record State Activity by Using History Junctions.

Diagnostic level: Error

Invalid Intersection

States and junctions must not overlap in the Stateflow Editor. To resolve this issue, avoid intersections by separating the states and junctions.

Diagnostic level: Error

Invalid Transitions Crossing into Graphical Function

Transitions must not enter a graphical function. Stateflow charts call graphical functions from state actions or transitions. To resolve this issue, delete the transition entering the graphical function. For more information, see Reuse Logic Patterns by Defining Graphical Functions.

Diagnostic level: Error

Invalid Transitions Crossing Out of Graphical Function

Transitions must not exit a graphical function. Flow charts in graphical functions must be completely contained inside the function. To resolve this issue, delete the transition exiting the graphical function. For more information, see Reuse Logic Patterns by Defining Graphical Functions.

Diagnostic level: Error

Invalid Use of Keywords as Function Arguments

A function definition uses a reserved keyword as an argument. To resolve this issue, rename the argument to the function. For a list of reserved keywords, see Rules for Naming Stateflow Objects.

Diagnostic level: Error

Monitoring Leaf or Child State Activity of Parallel States

Charts and states with parallel (AND) decomposition do not support monitoring of leaf or child state activity because parallel substates are active simultaneously. To resolve this issue, open the Property Inspector or the Model Explorer. Clear the Create output for monitoring check box or select Self activity from the drop-down list. For more information, see Monitor State Activity Through Active State Data.

Diagnostic level: Warning

Object Contains a Syntax Error

In a state or transition, an action or condition does not follow the syntax rules. The Stateflow Editor underlines syntax errors with a red, wavy line. For more information, see Transition Label Notation and State Labels.

Diagnostic level: Error

Note

In the parent chart, subcharts with syntax errors are highlighted in red and an error badge indicates the syntax issue. In the subchart editor, the syntax error is underlined in red, but there is no badge to indicate the issue.

Transition Action Precedes a Condition Action Along This Path

When a transition with a transition action is followed by a transition with a condition action, the actions are not executed in the order of the transitions. Stateflow charts execute condition actions when the associated condition is evaluated as true. In contrast, charts execute transition actions only when the transition path is fully executed.

For example, suppose that ConditionA and ConditionB are true.

Executing the transition path from state A to state B follows this order:

  • State A is active.

  • The chart evaluates ConditionA.

  • The chart evaluates ConditionB.

  • The chart executes ConditionAction2.

  • State A becomes inactive.

  • The chart executes TransitionAction1.

  • State B becomes active.

As a result, ConditionAction2 occurs before TransitionAction1.

To improve the clarity of the chart, place the transition action after the last condition action on the path.

Diagnostic configuration parameter: Transition action specified before condition action (Simulink)

Transition Begins or Ends in a Parallel State

In charts and states with parallel (AND) decomposition, transitions leading to or from substates cause all sibling states to become active or inactive. To resolve this issue, remove the transitions or change the decomposition of the parent state to exclusive (OR). For more information, see State Decomposition.

Diagnostic level: Warning

Transition Crosses Parallel States

Standalone Stateflow charts do not support transitions that cross the boundary of a parallel state. To resolve this issue, delete the transition crossing into or out of the parallel states.

Diagnostic level: Error

Transition Loops Outside Natural Parent

If a transition goes outside the parent state between the source and destination, the exit and entry actions of the parent state execute before the destination state becomes active.

For example, consider the highlighted transition in this chart.

When this transition becomes active, the state actions are executed in this order:

  • exit actions in state B

  • exit actions in state A

  • entry actions in state A

  • entry actions in state C

To prevent the chart from exiting and reentering state A, move the transition so that it is contained within state A.

Diagnostic configuration parameter: Transition outside natural parent (Simulink)

Transition Shadowing

When an unconditional transition executes before other outgoing transitions from the same source, it prevents the other transitions from executing. To avoid transition shadowing:

  • Create no more than one unconditional transition from each state or junction.

  • Explicitly specify that the unconditional transition executes after any transitions with conditions.

For more information, see Transition Evaluation Order.

Diagnostic configuration parameter: Unreachable execution path (Simulink)

Unconditional Path Out of State with During Actions or Child States

Unconditional transitions leading out of a state inhibit:

  • The execution of the during actions in the state.

  • The default transitions to child states.

To resolve this issue, add transition conditions.

Diagnostic configuration parameter: Transition outside natural parent (Simulink)

Unexpected Backtracking

Unintended backtracking of control flow can occur at a junction when these conditions are true:

  • The junction does not have an unconditional transition path to a state or terminating junction.

  • Multiple transition paths that share a source lead to the junction.

For more information, see Backtrack in Flow Charts.

For example, suppose that ConditionA and ConditionB are true and ConditionC is false.

Then executing the default transition path to state A follows this order:

  • The default transition leads to the first junction.

  • The chart evaluates ConditionA. Since this condition is true, the chart executes Action1 and moves to the second junction.

  • The chart evaluates ConditionC. Since this condition is false, the chart backtracks to the first junction.

  • The chart evaluates ConditionB. Since this condition is true, the chart executes Action2 and moves to the second junction.

  • The chart evaluates ConditionC. Since this condition is false, the chart backtracks to the first junction.

  • The chart executes Action3.

  • State A becomes active.

As a result, the chart executes the three condition actions.

To avoid backtracking, combine the conditions and create an unconditional path from the second junction to the destination state.

Diagnostic configuration parameter: Unexpected backtracking (Simulink)

Unreachable State or Unreachable Junction

A state or junction is unreachable when no valid execution path leads to it. To resolve this issue, connect the unreachable state or junction with a transition from a reachable state or junction.

Diagnostic configuration parameter: Unreachable execution path (Simulink)

Unused Function

A function is unused when a chart when there are no statements that call the function. To resolve this issue, call the function from a state or transition action or from another function.

Diagnostic level: Warning

Related Topics