Commit 62068b7b authored by Robert Bradshaw's avatar Robert Bradshaw

Trac 676 - arithmetic is always at least an int

parent 6100f407
...@@ -5295,7 +5295,8 @@ class UnaryPlusNode(UnopNode): ...@@ -5295,7 +5295,8 @@ class UnaryPlusNode(UnopNode):
operator = '+' operator = '+'
def analyse_c_operation(self, env): def analyse_c_operation(self, env):
self.type = self.operand.type self.type = PyrexTypes.widest_numeic_type(
self.operand.type, PyreXTypes.c_int_type)
def py_operation_function(self): def py_operation_function(self):
return "PyNumber_Positive" return "PyNumber_Positive"
...@@ -5314,7 +5315,8 @@ class UnaryMinusNode(UnopNode): ...@@ -5314,7 +5315,8 @@ class UnaryMinusNode(UnopNode):
def analyse_c_operation(self, env): def analyse_c_operation(self, env):
if self.operand.type.is_numeric: if self.operand.type.is_numeric:
self.type = self.operand.type self.type = PyrexTypes.widest_numeric_type(
self.operand.type, PyrexTypes.c_int_type)
else: else:
self.type_error() self.type_error()
if self.type.is_complex: if self.type.is_complex:
...@@ -5339,7 +5341,8 @@ class TildeNode(UnopNode): ...@@ -5339,7 +5341,8 @@ class TildeNode(UnopNode):
def analyse_c_operation(self, env): def analyse_c_operation(self, env):
if self.operand.type.is_int: if self.operand.type.is_int:
self.type = self.operand.type self.type = PyrexTypes.widest_numeric_type(
self.operand.type, PyrexTypes.c_int_type)
else: else:
self.type_error() self.type_error()
...@@ -5374,7 +5377,10 @@ class DecrementIncrementNode(CUnopNode): ...@@ -5374,7 +5377,10 @@ class DecrementIncrementNode(CUnopNode):
# unary ++/-- operator # unary ++/-- operator
def analyse_c_operation(self, env): def analyse_c_operation(self, env):
if self.operand.type.is_ptr or self.operand.type.is_numeric: if self.operand.type.is_numeric:
self.type = PyrexTypes.widest_numeric_type(
self.operand.type, PyrexTypes.c_int_type)
elif self.operand.type.is_ptr:
self.type = self.operand.type self.type = self.operand.type
else: else:
self.type_error() self.type_error()
...@@ -5913,6 +5919,9 @@ class NumBinopNode(BinopNode): ...@@ -5913,6 +5919,9 @@ class NumBinopNode(BinopNode):
if self.operator not in '|^&': if self.operator not in '|^&':
# False + False == 0 # not False! # False + False == 0 # not False!
widest_type = PyrexTypes.c_int_type widest_type = PyrexTypes.c_int_type
else:
widest_type = PyrexTypes.widest_numeric_type(
widest_type, PyrexTypes.c_int_type)
return widest_type return widest_type
else: else:
return None return None
......
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