diff options
author | da-woods <dw-git@d-woods.co.uk> | 2021-12-18 20:05:48 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-18 21:05:48 +0100 |
commit | ba37c35ca4da7edd099ffa6832e23764b0bf9bd9 (patch) | |
tree | 10f9dc4401d7cd3df02e4746dd3be315f993925a | |
parent | ea43f8ef66a71a5f6c03a24bfd69d603dcd5388e (diff) | |
download | cython-ba37c35ca4da7edd099ffa6832e23764b0bf9bd9.tar.gz |
Remove ban on assignment to reference (GH-3987)
Fixes https://github.com/cython/cython/issues/1863
-rw-r--r-- | Cython/Compiler/ExprNodes.py | 2 | ||||
-rw-r--r-- | tests/run/lvalue_refs.pyx | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 303492423..f6814cb5b 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -2136,8 +2136,6 @@ class NameNode(AtomicExprNode): if self.type.is_const: error(self.pos, "Assignment to const '%s'" % self.name) - if self.type.is_reference: - error(self.pos, "Assignment to reference '%s'" % self.name) if not self.is_lvalue(): error(self.pos, "Assignment to non-lvalue '%s'" % self.name) self.type = PyrexTypes.error_type diff --git a/tests/run/lvalue_refs.pyx b/tests/run/lvalue_refs.pyx index c70744533..7cf18df52 100644 --- a/tests/run/lvalue_refs.pyx +++ b/tests/run/lvalue_refs.pyx @@ -29,6 +29,18 @@ def test_lvalue_ref_assignment(): assert bar[0] == &baz[0][0] assert bar[0][0] == bongle +cdef void assign_to_basic_reference(int& ref): + ref = 123 + +def test_assign_to_basic_ref(): + """ + >>> test_assign_to_basic_ref() + 123 + """ + cdef int x=0 + assign_to_basic_reference(x) + print x + # not *strictly* lvalue refs but this file seems the closest applicable place for it. # GH 3754 - std::vector operator[] returns a reference, and this causes problems if # the reference is passed into Cython __Pyx_GetItemInt |