Skip to content

Commit a5c65df

Browse files
committed
Fix incomplete checks in infinite fallthrough detection
1 parent 74f3e9a commit a5c65df

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

nmfu.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -4968,26 +4968,28 @@ def _verify_fallthrough_loop(self):
49684968
if not transition.is_fallthrough:
49694969
continue
49704970

4971-
# TODO: this should really be extracted into a method
49724971
visited = set()
4972+
def consider(transition):
4973+
return not any(x.get_target_override_mode() in [ActionOverrideMode.ALWAYS_GOTO_OTHER, ActionOverrideMode.ALWAYS_GOTO_UNDEFINED] and transition.target not in x.get_target_override_targets() for x in transition.actions)
4974+
49734975
def aux(x):
49744976
if isinstance(x, DFConditionPoint):
49754977
for i in x.transitions:
49764978
if i.target in visited:
49774979
continue
4978-
visited.add(i.target)
4979-
aux(i.target)
4980+
if consider(i):
4981+
visited.add(i.target)
4982+
aux(i.target)
49804983
else:
49814984
real_target = x[transition.on_values]
4982-
if real_target and real_target.is_fallthrough:
4985+
if real_target and real_target.is_fallthrough and consider(real_target):
49834986
if real_target.target not in visited:
49844987
visited.add(real_target.target)
49854988
aux(real_target.target)
49864989

49874990
aux(state)
49884991

4989-
if state in visited and transition.is_fallthrough and not any(x.get_target_override_mode() in [
4990-
ActionOverrideMode.ALWAYS_GOTO_OTHER, ActionOverrideMode.ALWAYS_GOTO_UNDEFINED] and state not in x.get_target_override_targets() for x in transition.actions):
4992+
if state in visited:
49914993
raise IllegalDFAStateError("Infinite loop due to self-referential fallthrough", transition)
49924994

49934995

0 commit comments

Comments
 (0)