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.
Edit-Time Check Issue | Diagnostic Configuration Parameter |
---|---|
Dangling transition | Unreachable execution path (Simulink) |
Default transition path does not terminate in a state | No unconditional default transitions (Simulink) |
Transition action precedes a condition action along this path | Transition action specified before condition action (Simulink) |
Transition loops outside natural parent | Transition outside natural parent (Simulink) |
Transition shadowing | Unreachable execution path (Simulink) |
Unconditional path out of state with during actions or child states | Transition outside natural parent (Simulink) |
Unexpected backtracking | Unexpected backtracking (Simulink) |
Unreachable junction | Unreachable execution path (Simulink) |
Unreachable port or junction | Unreachable execution path (Simulink) |
Unreachable state | Unreachable execution path (Simulink) |
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.
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 Use Default Transitions to Specify Initial Substate Activity.
Graphical function contains a state
Issue: Because graphical functions execute completely in a single time step, they must not contain any states.
Diagnostic level: Error.
Solution: Replace the states with junctions. For more information, see Reuse Logic Patterns by Defining Graphical Functions.
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.
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 Define Actions in a State.
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 source.
Edit-Time Checks on Transitions
Dangling transition
Issue: Every transition must have a valid destination.
Diagnostic level: Depends on the configuration parameter Unreachable execution path (Simulink).
Solution: Connect the transition to a state, junction, or port. For more information, see Transition Between Operating Modes.
Default transition path does not terminate in a state
Issue: In charts or states with exclusive (OR) decomposition and at least one substate:
Every branch of the default transition path must lead to a substate.
There must be a branch of the 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 branch of the default transition path in a substate. Ensure that one branch of the 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.
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 Define Actions in a Transition.
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 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).
Transition connects to a box
Issue: Transitions must connect only to states and junctions.
Diagnostic level: Error.
Solution: Move or delete the transitions attached to the 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.
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.
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.
Transition loops outside natural parent
Issue: If a transition goes outside the parent state between the source and destination, the chart executes the
exit
andentry
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 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.
Unconditional path out of state with during actions or child states
Issue: Unconditional transitions leading out of a state prevent the execution of the
during
actions in the state and the transitions between 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.
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 Resume Prior Substate 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.
Transition paths from same source have different parents
Issue: Transition paths start at the same source state but have different parents.
Diagnostic level: Error.
Solution: Modify transition paths to have the same parent.
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 path to state
A
. IfConditionA
andConditionB
are true andConditionC
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 (Simulink).
Solution: Connect the unreachable junction with a transition from a reachable source.
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.
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.
Edit-Time Checks on Entry and Exit Ports
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 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.
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 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.
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.
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.
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.
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.
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.
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.
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.
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.
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 source.