Commit de698936 authored by Stefan Behnel's avatar Stefan Behnel

Do not evaluate DEF statements inside of IF blocks with false conditions.

Closes #1796
parent 0b0a2e57
...@@ -2160,6 +2160,7 @@ def p_DEF_statement(s): ...@@ -2160,6 +2160,7 @@ def p_DEF_statement(s):
name = p_ident(s) name = p_ident(s)
s.expect('=') s.expect('=')
expr = p_compile_time_expr(s) expr = p_compile_time_expr(s)
if s.compile_time_eval:
value = expr.compile_time_value(denv) value = expr.compile_time_value(denv)
#print "p_DEF_statement: %s = %r" % (name, value) ### #print "p_DEF_statement: %s = %r" % (name, value) ###
denv.declare(name, value) denv.declare(name, value)
......
...@@ -42,3 +42,33 @@ def h(): ...@@ -42,3 +42,33 @@ def h():
ELSE: ELSE:
i = 3 i = 3
return i return i
def control_flow_DEF1():
"""
>>> control_flow_DEF1()
B should be 2.
2
"""
IF YES:
DEF B=2
print('B should be 2.')
ELSE:
DEF B=3
print('B should be 3.')
return B
def control_flow_DEF2():
"""
>>> control_flow_DEF2()
B should be 3.
3
"""
IF NO:
DEF B=2
print('B should be 2.')
ELSE:
DEF B=3
print('B should be 3.')
return B
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment