Commit 595c2453 authored by Stefan Behnel's avatar Stefan Behnel

fixes for True/False in compile time expressions; make sure True/False pass as...

fixes for True/False in compile time expressions; make sure True/False pass as objects (not just ints) where possible
parent ca3ecf6a
......@@ -489,7 +489,7 @@ class ExprNode(Node):
src = CoerceFromPyTypeNode(dst_type, src, env)
else: # neither src nor dst are py types
# Added the string comparison, since for c types that
# is enough, but SageX gets confused when the types are
# is enough, but Cython gets confused when the types are
# in different files.
if not (str(src.type) == str(dst_type) or dst_type.assignable_from(src_type)):
error(self.pos, "Cannot assign type '%s' to '%s'" %
......@@ -588,7 +588,7 @@ class BoolNode(PyConstNode):
def coerce_to(self, dst_type, env):
value = self.value
if dst_type.is_numeric:
return IntNode(self.pos, value=self.value).coerce_to(dst_type, env)
return IntNode(self.pos, value=int(self.value)).coerce_to(dst_type, env)
else:
return PyConstNode.coerce_to(self, dst_type, env)
......
......@@ -469,9 +469,9 @@ def p_atom(s):
if name == "None":
return ExprNodes.NoneNode(pos)
elif name == "True":
return ExprNodes.BoolNode(pos, value=1)
return ExprNodes.BoolNode(pos, value=True)
elif name == "False":
return ExprNodes.BoolNode(pos, value=0)
return ExprNodes.BoolNode(pos, value=False)
else:
return p_name(s, name)
elif sy == 'NULL':
......@@ -489,7 +489,9 @@ def p_name(s, name):
pass
else:
rep = repr(value)
if isinstance(value, int):
if isinstance(value, bool):
return ExprNodes.BoolNode(pos, value = value)
elif isinstance(value, int):
return ExprNodes.IntNode(pos, value = rep)
elif isinstance(value, long):
return ExprNodes.LongNode(pos, value = rep)
......
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