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,9 +2160,10 @@ def p_DEF_statement(s):
name = p_ident(s)
s.expect('=')
expr = p_compile_time_expr(s)
value = expr.compile_time_value(denv)
#print "p_DEF_statement: %s = %r" % (name, value) ###
denv.declare(name, value)
if s.compile_time_eval:
value = expr.compile_time_value(denv)
#print "p_DEF_statement: %s = %r" % (name, value) ###
denv.declare(name, value)
s.expect_newline("Expected a newline", ignore_semicolon=True)
return Nodes.PassStatNode(pos)
......
......@@ -42,3 +42,33 @@ def h():
ELSE:
i = 3
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