Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
595fd56e
Commit
595fd56e
authored
Nov 10, 2011
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Be more careful about allowing assignment with array types.
parent
50cba685
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
11 deletions
+37
-11
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+10
-2
tests/errors/e_ass.pyx
tests/errors/e_ass.pyx
+27
-9
No files found.
Cython/Compiler/ExprNodes.py
View file @
595fd56e
...
...
@@ -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
)
...
...
tests/errors/e_ass.pyx
View file @
595fd56e
# mode: error
cdef
void
foo
(
obj
):
cdef
int
i1
cdef
char
*
p1
cdef
int
*
p2
i1
=
p1
# error
p2
=
obj
# error
cdef
int
i1
cdef
char
*
p1
cdef
int
*
p2
i1
=
p1
# error
p2
=
obj
# error
obj
=
p2
# error
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
"""
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment