Commit 4692dff4 authored by scoder's avatar scoder Committed by GitHub

Merge pull request #1799 from scoder/fix_DEF_flow

Do not evaluate DEF statements inside of IF blocks with false condiions
parents 3fdf3002 de698936
......@@ -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