Commit c55441f7 authored by Robert Bradshaw's avatar Robert Bradshaw

Various test fixes.

parent 3d641eac
......@@ -3274,10 +3274,8 @@ class IndexNode(ExprNode):
(index, base_type))
self.type = PyrexTypes.error_type
else:
error(self.pos,
"Can't use non-constant indices for '%s'" %
base_type)
self.type = PyrexTypes.error_type
self.base = self.base.coerce_to_pyobject(env)
return self.analyse_base_and_index_types(env, getting=getting, setting=setting, analyse_base=False)
else:
error(self.pos,
"Attempting to index non-array type '%s'" %
......@@ -4456,7 +4454,7 @@ class SimpleCallNode(CallNode):
func_type = self.function_type()
if func_type.is_pyobject:
self.arg_tuple = TupleNode(self.pos, args = self.args)
self.arg_tuple = self.arg_tuple.analyse_types(env)
self.arg_tuple = self.arg_tuple.analyse_types(env).coerce_to_pyobject(env)
self.args = None
if func_type is Builtin.type_type and function.is_name and \
function.entry and \
......@@ -6455,10 +6453,10 @@ class TupleNode(SequenceNode):
gil_message = "Constructing Python tuple"
def infer_type(self, env):
if self.mult_factor:
if self.mult_factor or not self.args:
return tuple_type
arg_types = [arg.infer_type(env) for arg in self.args]
if any(type.is_pyobject or type.is_unspecified for type in arg_types):
if any(type.is_pyobject or type.is_unspecified or type.is_fused for type in arg_types):
return tuple_type
else:
type = PyrexTypes.c_tuple_type(arg_types)
......@@ -6473,7 +6471,7 @@ class TupleNode(SequenceNode):
else:
if not skip_children:
self.args = [arg.analyse_types(env) for arg in self.args]
if not self.mult_factor and not any(arg.type.is_pyobject for arg in self.args):
if not self.mult_factor and not any(arg.type.is_pyobject or arg.type.is_fused for arg in self.args):
self.type = PyrexTypes.c_tuple_type(arg.type for arg in self.args)
env.declare_tuple_type(self.pos, self.type)
self.is_temp = 1
......@@ -6496,11 +6494,15 @@ class TupleNode(SequenceNode):
return node
def coerce_to(self, dst_type, env):
if self.type.is_ctuple and dst_type.is_ctuple and self.type.size == dst_type.size:
if self.type.is_ctuple:
if dst_type.is_ctuple and self.type.size == dst_type.size:
if self.type == dst_type:
return self
coerced_args = [arg.coerce_to(type, env) for arg, type in zip(self.args, dst_type.components)]
return TupleNode(self.pos, args=coerced_args, type=dst_type, is_temp=1)
elif dst_type is tuple_type or dst_type is py_object_type:
coerced_args = [arg.coerce_to_pyobject(env) for arg in self.args]
return TupleNode(self.pos, args=coerced_args, type=tuple_type, is_temp=1).analyse_types(env, skip_children=True)
else:
return SequenceNode.coerce_to(self, dst_type, env)
......@@ -8046,6 +8048,9 @@ class DefaultsTupleNode(TupleNode):
args.append(arg)
super(DefaultsTupleNode, self).__init__(pos, args=args)
def analyse_types(self, env, skip_children=False):
return super(DefaultsTupleNode, self).analyse_types(env, skip_children).coerce_to_pyobject(env)
class DefaultsKwDictNode(DictNode):
# CyFunction's __kwdefaults__ dict
......
......@@ -729,7 +729,7 @@ class FusedCFuncDefNode(StatListNode):
if self.py_func:
args = [CloneNode(default) for default in defaults if default]
self.defaults_tuple = TupleNode(self.pos, args=args)
self.defaults_tuple = self.defaults_tuple.analyse_types(env, skip_children=True)
self.defaults_tuple = self.defaults_tuple.analyse_types(env, skip_children=True).coerce_to_pyobject(env)
self.defaults_tuple = ProxyNode(self.defaults_tuple)
self.code_object = ProxyNode(self.specialized_pycfuncs[0].code_object)
......
......@@ -4890,6 +4890,9 @@ class SingleAssignmentNode(AssignmentNode):
from . import ExprNodes, UtilNodes
if not isinstance(self.lhs, ExprNodes.TupleNode):
return
for arg in self.lhs.args:
if arg.is_starred:
return
unrolled = self.unroll(self.rhs, len(self.lhs.args), env)
if not unrolled:
......@@ -5581,7 +5584,7 @@ class AssertStatNode(StatNode):
# prevent tuple values from being interpreted as argument value tuples
from .ExprNodes import TupleNode
value = TupleNode(value.pos, args=[value], slow=True)
self.value = value.analyse_types(env, skip_children=True)
self.value = value.analyse_types(env, skip_children=True).coerce_to_pyobject(env)
else:
self.value = value.coerce_to_pyobject(env)
return self
......
......@@ -32,8 +32,10 @@ def simple():
assert typeof(u) == "unicode object", typeof(u)
L = [1,2,3]
assert typeof(L) == "list object", typeof(L)
t = (4,5,6)
t = (4,5,6,())
assert typeof(t) == "tuple object", typeof(t)
t2 = (4, 5.0, 6)
assert typeof(t2) == "(long, double, long)", typeof(t)
def builtin_types():
"""
......@@ -80,7 +82,7 @@ def slicing():
assert typeof(L1) == "list object", typeof(L1)
L2 = L[1:2:2]
assert typeof(L2) == "list object", typeof(L2)
t = (4,5,6)
t = (4,5,6,())
assert typeof(t) == "tuple object", typeof(t)
t1 = t[1:2]
assert typeof(t1) == "tuple object", typeof(t1)
......@@ -107,7 +109,7 @@ def indexing():
assert typeof(L) == "list object", typeof(L)
L1 = L[1]
assert typeof(L1) == "Python object", typeof(L1)
t = (4,5,6)
t = (4,5,())
assert typeof(t) == "tuple object", typeof(t)
t1 = t[1]
assert typeof(t1) == "long", typeof(t1)
......
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