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): ...@@ -489,7 +489,7 @@ class ExprNode(Node):
src = CoerceFromPyTypeNode(dst_type, src, env) src = CoerceFromPyTypeNode(dst_type, src, env)
else: # neither src nor dst are py types else: # neither src nor dst are py types
# Added the string comparison, since for c types that # 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. # in different files.
if not (str(src.type) == str(dst_type) or dst_type.assignable_from(src_type)): if not (str(src.type) == str(dst_type) or dst_type.assignable_from(src_type)):
error(self.pos, "Cannot assign type '%s' to '%s'" % error(self.pos, "Cannot assign type '%s' to '%s'" %
...@@ -588,7 +588,7 @@ class BoolNode(PyConstNode): ...@@ -588,7 +588,7 @@ class BoolNode(PyConstNode):
def coerce_to(self, dst_type, env): def coerce_to(self, dst_type, env):
value = self.value value = self.value
if dst_type.is_numeric: 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: else:
return PyConstNode.coerce_to(self, dst_type, env) return PyConstNode.coerce_to(self, dst_type, env)
......
...@@ -469,9 +469,9 @@ def p_atom(s): ...@@ -469,9 +469,9 @@ def p_atom(s):
if name == "None": if name == "None":
return ExprNodes.NoneNode(pos) return ExprNodes.NoneNode(pos)
elif name == "True": elif name == "True":
return ExprNodes.BoolNode(pos, value=1) return ExprNodes.BoolNode(pos, value=True)
elif name == "False": elif name == "False":
return ExprNodes.BoolNode(pos, value=0) return ExprNodes.BoolNode(pos, value=False)
else: else:
return p_name(s, name) return p_name(s, name)
elif sy == 'NULL': elif sy == 'NULL':
...@@ -489,7 +489,9 @@ def p_name(s, name): ...@@ -489,7 +489,9 @@ def p_name(s, name):
pass pass
else: else:
rep = repr(value) 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) return ExprNodes.IntNode(pos, value = rep)
elif isinstance(value, long): elif isinstance(value, long):
return ExprNodes.LongNode(pos, value = rep) 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