Commit 595fd56e authored by Robert Bradshaw's avatar Robert Bradshaw

Be more careful about allowing assignment with array types.

parent 50cba685
......@@ -2440,6 +2440,8 @@ class IndexNode(ExprNode):
def analyse_target_types(self, env):
self.analyse_base_and_index_types(env, setting = 1)
if not self.is_lvalue():
error(self.pos, "Assignment to non-lvalue of type '%s'" % self.type)
def analyse_base_and_index_types(self, env, getting = 0, setting = 0, analyse_base = True):
# Note: This might be cleaned up by having IndexNode
......@@ -2803,7 +2805,11 @@ class IndexNode(ExprNode):
return self.base.check_const_addr() and self.index.check_const()
def is_lvalue(self):
return 1
base_type = self.base.type
if self.type.is_ptr or self.type.is_array:
return not base_type.base_type.is_array
else:
return True
def calculate_result_code(self):
if self.is_buffer_access:
......@@ -4091,6 +4097,8 @@ class AttributeNode(ExprNode):
def analyse_target_types(self, env):
self.analyse_types(env, target = 1)
if not self.is_lvalue():
error(self.pos, "Assignment to non-lvalue of type '%s'" % self.type)
def analyse_types(self, env, target = 0):
self.initialized_check = env.directives['initializedcheck']
......@@ -4295,7 +4303,7 @@ class AttributeNode(ExprNode):
def is_lvalue(self):
if self.obj:
return 1
return not self.type.is_array
else:
return NameNode.is_lvalue(self)
......
......@@ -9,8 +9,26 @@ cdef void foo(obj):
obj = p2 # error
ctypedef int[1] int_array
cdef int_array x, y
x = y # error
cdef int_array *x_ptr = &x
x_ptr[0] = y # error
cdef class A:
cdef int_array value
def __init__(self):
self.value = x # error
_ERRORS = u"""
7:16: Cannot assign type 'char *' to 'int'
8:17: Cannot convert Python object to 'int *'
10:17: Cannot convert 'int *' to Python object
17:2: Assignment to non-lvalue 'x'
20:5: Assignment to non-lvalue of type 'int_array'
25:12: Assignment to non-lvalue of type 'int_array'
7:19: Cannot assign type 'char *' to 'int'
8:20: Cannot convert Python object to 'int *'
10:20: Cannot convert 'int *' to Python object
"""
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