Main Content

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.

Edit-Time Checks on States

Invalid Intersection

  • Issue: States and junctions must not overlap in the Stateflow Editor.

  • Diagnostic level: Error.

  • Solution: Avoid intersections by separating the states and junctions.

Monitoring Leaf or Child State Activity of Parallel States

  • Issue: Charts and states with parallel (AND) decomposition do not support monitoring of leaf or child state activity because parallel substates are active simultaneously.

  • Diagnostic level: Warning.

  • Solution: 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.

Object Contains a Syntax Error

  • Issue: A state action does not follow the Stateflow syntax rules. The Stateflow Editor underlines syntax errors with a red, wavy line.

  • Diagnostic level: Error.

  • Solution: Correct the syntax error in the state action. For more information, see State Labels.

    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.

Unreachable State

  • Issue: A state is unreachable when no valid execution path leads to it.

  • Diagnostic level: Depends on the configuration parameter Unreachable execution path.

  • Solution: Connect the unreachable state with a transition from a reachable state or junction.

Edit-Time Checks on Transitions

Dangling Transition

  • Issue: Every transition must have a valid destination state or junction.

  • Diagnostic level: Depends on the configuration parameter Unreachable execution path.

  • Solution: Connect the transition to a state or junction. For more information, see Transitions.

Default Transition Is Missing

  • Issue: 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.

  • Diagnostic level: Error.

  • Solution: Specify an initial state by adding a default transition. For more information, see Default Transitions.

Default Transition Path Does Not Terminate in a State

  • Issue: 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.

  • Diagnostic level: Depends on the configuration parameter No unconditional default transitions.

  • Solution: Terminate every path along the default transition in a substate. Ensure that one default transition path is not guarded by a condition or triggered by an event.

Invalid Default Transition Path

  • Issue: A default transition path must not exit the parent state.

  • Diagnostic level: Error.

  • Solution: Modify the default transition path so it stays within the parent state.

Invalid Transitions Crossing into Graphical Function

  • Issue: Transitions must not enter a graphical function. Stateflow charts call graphical functions from state actions or transitions.

  • Diagnostic level: Error.

  • Solution: Delete the transition entering the graphical function.

Object Contains a Syntax Error

  • Issue: In a transition, a condition or action does not follow the Stateflow syntax rules. The Stateflow Editor underlines syntax errors with a red, wavy line.

  • Diagnostic level: Error.

  • Solution: Correct the syntax error in the transition condition or action. For more information, see Transition Labels.

Transition Action Precedes a Condition Action Along This Path

  • Issue: 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. As a consequence, a chart takes a transition path, the condition actions occur before the transition actions.

  • Diagnostic level: Depends on the configuration parameter Transition action specified before condition action.

  • Solution: Place the transition action after the last condition action on the path.

Transition Begins or Ends in a Parallel State

  • Issue: In charts and states with parallel (AND) decomposition, all sibling states are active or inactive at the same time.

  • Diagnostic level: Warning.

  • Solution: Remove the transitions or change the decomposition of the parent state to exclusive (OR).

Transition Connects to a Box

  • Issue: Transitions can only connect to states and junctions.

  • Diagnostic level: Error.

  • Solution: Move or delete the transitions attached to the box.

Transition Crosses Parallel States

  • Issue: Standalone Stateflow charts do not support transitions that cross the boundary of a parallel state.

  • Diagnostic level: Error.

  • Solution: Delete the transition crossing into or out of the parallel states.

Transition Enters or Exits Graphical Function

  • Issue: Transitions must not exit a graphical function. Flow charts in graphical functions must be completely contained inside the function.

  • Diagnostic level: Error.

  • Solution: Delete the transition exiting the graphical function.

Transition Loops Outside Natural Parent

  • Issue: If a transition goes outside the parent state between the source and destination, the chart executes the exit and entry actions of the parent state before the destination state becomes active.

  • Diagnostic level: Depends on the configuration parameter Transition outside natural parent.

  • Solution: Move the transition so that it is contained within the parent state.

Transition Shadowing

  • Issue: When an unconditional transition executes before other outgoing transitions from the same source, it prevents the other transitions from executing.

  • Diagnostic level: Depends on the configuration parameter Unreachable execution path.

  • Solution: 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.

Unconditional Path Out of State with During Actions or Child States

  • Issue: Unconditional transitions leading out of a state inhibit the execution of the during actions in the state and the default transitions to child states.

  • Diagnostic level: Depends on the configuration parameter Transition outside natural parent.

  • Solution: Add a condition to the transition or remove during actions and child states from the state.

Edit-Time Checks on Junctions

Cycle Contains Transitions with Transition Actions

  • Issue: Cycles should not contain transitions with transition actions.

  • Diagnostic level: Error.

  • Solution: Remove the transition action or remove the cycle by deleting a transition.

Invalid History Junction

  • Issue: 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.

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

    • The history junction is the source of a transition.

  • Diagnostic level: Error.

  • Solution: Remove the history junction from the chart level of the hierarchy, a state with parallel (AND) decomposition, or a graphical function. Remove all but one history junction from the state. Move the transition source to a connective junction or a state. For more information, see Record State Activity by Using History Junctions.

Junction Has No Unconditional Escape from Cycle

  • Issue: A junction must have an unconditional escape path from a cycle to a state or terminating junction.

  • Diagnostic level: Error.

  • Solution: Create an unconditional path from the junction to a state or terminating junction.

Unexpected Backtracking

  • Issue: Unintended backtracking of control flow can occur when:

    • Multiple transition paths from the same source lead to a junction.

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

  • Diagnostic level: Depends on the configuration parameter Unexpected backtracking.

  • Solution: Create an unconditional path from the junction to a state or terminating junction. For more information, see Backtrack in Flow Charts.

    For example, the highlighted junction in this chart does not have an unconditional transition path to state A. If ConditionA and ConditionB are true and ConditionC is false, the chart backtracks to the first junction in the path multiple times. 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. After the change, the chart executes only one condition action.

Unreachable Junction

  • Issue: A junction is unreachable when no valid execution path leads to it.

  • Diagnostic level: Depends on the configuration parameter Unreachable execution path.

  • Solution: Connect the unreachable junction with a transition from a reachable state or junction.

Edit-Time Checks on Functions

Function is Unused

  • Issue: A function is unused when a chart when there are no statements that call the function.

  • Diagnostic level: Warning.

  • Solution: Call the function from a state or transition action or from another function.

Graphical Function Contains a State

Invalid Use of Keywords as Function Arguments

  • Issue: A function definition uses a reserved keyword as an argument.

  • Diagnostic level: Error.

  • Solution: Rename the argument to the function. For a list of reserved keywords, see Rules for Naming Stateflow Objects.

Related Topics