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. Edit-time checks can also be disabled by using edittime.setDisplayIssues (Simulink).

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 and Subcharts

Atomic subchart contains state actions

  • Issue: State actions are not supported on atomic subcharts.

  • Diagnostic level: Error.

  • Solution: Delete the state actions or move them to a substate of the atomic subchart.

    Atomic subchart that contains state actions.

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.

    Chart with no default transition.

Graphical function contains a state

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.

    Invalid intersection between states.

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.

    Parallel substates in a state that monitors child state activity.

State 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. See also Transition Contains a Syntax Error.

  • Diagnostic level: Error.

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

    State that contains a syntax 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.

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 (Simulink).

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

    Chart that contains an unreachable state.

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 (Simulink).

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

    Chart that contains a dangling transition.

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 (Simulink).

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

    Chart without an unconditional default transition path to a state.

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.

    Chart with an invalid default transition path.

Transition 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. See also State Contains a Syntax Error.

  • Diagnostic level: Error.

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

    Transition that contains a syntax error.

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 (Simulink).

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

    Transition path in which a transition action precedes a condition action.

Transition begins or ends in a parallel state

  • Issue: In charts and states with parallel (AND) decomposition, all sibling substates 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).

    Transitions that begin or end in a parallel states.

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.

    Chart with a transition that connects to a box.

Transition crosses parallel states

  • Issue: Standalone charts in MATLAB® 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.

    Standalone chart with a transition that crosses the boundary of a parallel state.

Transition enters or exits graphical function

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

  • Diagnostic level: Error.

  • Solution: Delete the transition entering or exiting the graphical function.

    Chart containing transitions that enter and exit a graphical function.

Transition is not connected to entry/exit port

  • Issue: Transition is not connected to the entry or exit port near its source or destination.

  • Diagnostic level: Warning.

  • Solution: Connect the transition to the port or move the transition source or destination to a different location.

    Entry port that is located near the destination point of a default transition.

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 (Simulink).

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

    Transition between substates that goes outside the boundary of 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 (Simulink).

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

    The unconditional transition in this chart shadows the conditional transition.

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 (Simulink).

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

    Chart with one transition out of a state with during actions and another transition out of a state with child states.

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.

    Flow chart with a transition action in a cycle.

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.

    Chart that contains an invalid history junction.

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.

    Junction with no unconditional escape from a cycle.

Unexpected backtracking

  • Issue: Unexpected backtracking of control flow can occur when multiple transition paths from the same source lead to a junction and the junction does not have an unconditional path to a state or terminating junction.

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

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

    Chart with unexpected backtracking.

    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.

    Chart with no unexpected backtracking.

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 (Simulink).

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

    Chart that contains an unreachable 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.

    Chart containing an unused function.

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 Guidelines for Naming Stateflow Objects.

    Function that uses a reserved keyword as an argument.

Edit-Time Checks on Entry and Exit Ports

Entry or exit junction at top level of chart

  • Issue: Entry and exit junctions are supported only in exclusive (OR) states and atomic subcharts.

  • Diagnostic level: Error.

  • Solution: Move the junction to an exclusive (OR) state or atomic subchart or delete the junction.

    Entry and exit junctions on the top level of a chart.

Entry junctions must have an unconditional path to a state

  • Issue: An entry junction must have one transition path that is not guarded by a condition or triggered by an event.

  • Diagnostic level: Error.

  • Solution: Add an unconditional path from the entry junction to a state.

    Entry junction that connects to a single conditional path to a state.

Entry junctions must have outgoing transitions

  • Issue: An entry junction does not connect to an outgoing transition path.

  • Diagnostic level: Error.

  • Solution: Attach transitions to the entry junction or remove the junction.

    Entry junction that does not connect to a transition path.

Exit ports must have an unconditional path to a state

  • Issue: An exit port must have one transition path that is not guarded by a condition or triggered by an event.

  • Diagnostic level: Error.

  • Solution: Add an unconditional path from the exit port to a state.

    Exit port that connects to a single conditional path to a state.

Exit ports must have outgoing transitions

  • Issue: An exit port does not connect to an outgoing transition path.

  • Diagnostic level: Error.

  • Solution: Attach transitions to the exit port or remove the port.

    Exit port that does not connect to a transition path.

Invalid entry or exit junction

  • Issue: Entry and exit junctions are supported only in exclusive (OR) states and atomic subcharts.

  • Diagnostic level: Error.

  • Solution: Move the junction to an exclusive (OR) state or atomic subchart or delete the junction.

    Entry and exit junctions in parallel (AND) states.

Missing entry or exit junction

  • Issue: An entry or exit port must have a matching entry or exit junction.

  • Diagnostic level: Error.

  • Solution: Delete the port or create a matching junction with the same label.

    Entry and exit ports that do not have a matching junction.

Multiple entry or exit junctions with same label

  • Issue: Entry and exit junctions in the same parent must have unique labels.

  • Diagnostic level: Error.

  • Solution: Delete one of the junctions or change one of the labels.

    Two entry junctions that have the same label in1.

Path from entry junction contains a terminal junction

  • Issue: Every path from an entry junction must lead to a state.

  • Diagnostic level: Error.

  • Solution: Replace the terminal junction with a state.

    Entry junction that connects to a terminal junction.

Path from exit port contains a terminal junction

  • Issue: Every path from an exit port must lead to a state.

  • Diagnostic level: Error.

  • Solution: Replace the terminal junction with a state.

    Exit port that connects to a terminal junction.

Transition path from an entry junction to a history junction

  • Issue: Transition paths from entry junctions must not connect to history junctions.

  • Diagnostic level: Error.

  • Solution: Remove the path from the entry junction to the history junction.

    Entry junction that connects to a history junction.

Transition path from an inner transition to an exit junction

  • Issue: Inner transition paths must not connect to an exit junction.

  • Diagnostic level: Error.

  • Solution: Remove the path from the inner transition to the exit junction.

    State that contains an inner transition to an exit port.

Transition path from entry junction or to exit junction must be contained in parent

  • Issue: Transition paths that start at entry junctions or end at exit junctions must be contained in the parent state.

  • Diagnostic level: Error.

  • Solution: Modify the transition path to be contained in the parent state.

    Transition path that exits and re-enters a state before connecting to an exit junction.

Unreachable port or junction

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

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

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

    Chart that contains an unreachable entry junction and port.

Related Topics