Commit 2fccef53 authored by Craig Citro's avatar Craig Citro

Fix type inference on unary operators.

parent 8cd71f08
...@@ -4343,7 +4343,11 @@ class UnopNode(ExprNode): ...@@ -4343,7 +4343,11 @@ class UnopNode(ExprNode):
self.compile_time_value_error(e) self.compile_time_value_error(e)
def infer_type(self, env): def infer_type(self, env):
return self.operand.infer_type(env) operand_type = self.operand.infer_type(env)
if operand_type.is_pyobject:
return py_object_type
else:
return operand_type
def analyse_types(self, env): def analyse_types(self, env):
self.operand.analyse_types(env) self.operand.analyse_types(env)
......
...@@ -122,6 +122,27 @@ def arithmetic(): ...@@ -122,6 +122,27 @@ def arithmetic():
d = 1 * 1.5 ** 2 d = 1 * 1.5 ** 2
assert typeof(d) == "double", typeof(d) assert typeof(d) == "double", typeof(d)
cdef class some_class:
pass
def unary_operators():
"""
>>> unary_operators()
"""
cdef int x = 1
assert typeof(~x) == "int", typeof(~x)
cdef some_class obj
assert typeof(~obj) == "Python object", typeof(~obj)
a = int(1)
assert typeof(a) == "Python object", typeof(a)
b = not int(3)
assert typeof(b) == "int", typeof(b)
c = +int(3)
assert typeof(c) == "Python object", typeof(c)
d = -int(5)
assert typeof(d) == "Python object", typeof(d)
def builtin_type_operations(): def builtin_type_operations():
""" """
>>> builtin_type_operations() >>> builtin_type_operations()
......
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