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