exception while using else as a scope

This commit is contained in:
Dave Halter
2014-08-07 12:10:31 +02:00
parent ee65764c3a
commit 743d064e6d
2 changed files with 9 additions and 8 deletions

View File

@@ -35,13 +35,14 @@ UNSURE = Status(None, 'unsure')
def break_check(evaluator, base_scope, element_scope): def break_check(evaluator, base_scope, element_scope):
reachable = REACHABLE reachable = REACHABLE
if isinstance(element_scope, Flow): if isinstance(element_scope, Flow):
check_scope = element_scope
invert = False invert = False
if element_scope.command == 'else': if check_scope.command == 'else':
element_scope = element_scope.previous check_scope = check_scope.previous
invert = True invert = True
if element_scope.command == 'if' and element_scope.inputs: if check_scope.command == 'if' and check_scope.inputs:
types = evaluator.eval_statement(element_scope.inputs[0]) types = evaluator.eval_statement(check_scope.inputs[0])
values = set(x.py__bool__() for x in types) values = set(x.py__bool__() for x in types)
if len(values) == 1: if len(values) == 1:
reachable = Status.lookup_table[values.pop()] reachable = Status.lookup_table[values.pop()]
@@ -51,9 +52,9 @@ def break_check(evaluator, base_scope, element_scope):
return UNREACHABLE return UNREACHABLE
else: else:
return UNSURE return UNSURE
elif element_scope.command == 'try': elif check_scope.command in ('try', 'except', 'finally'):
reachable = UNSURE reachable = UNSURE
if base_scope != element_scope and base_scope != element_scope.parent: if base_scope != element_scope and base_scope != check_scope.parent:
return reachable & break_check(evaluator, base_scope, element_scope.parent) return reachable & break_check(evaluator, base_scope, element_scope.parent)
return reachable return reachable

View File

@@ -11,12 +11,12 @@ foo(1)
# Exceptions are not analyzed. So check both if branches # Exceptions are not analyzed. So check both if branches
def try_except(x): def try_except(x):
try: try:
if 1.0: if 0:
return 1 return 1
else: else:
return '' return ''
except AttributeError: except AttributeError:
return 1.0 return 1.0
#? int() float() #? float() str()
try_except(1) try_except(1)