diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2017-10-03 18:56:08 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2017-10-03 18:56:08 +0200 |
commit | 15ce8b91510117c2a25e08659c33ee3966d5131c (patch) | |
tree | fa2f6ced8a3a36aa4d46095b0f29653957cd3daa | |
parent | 0c651564295b667a1986882a0954be5c0e0565a5 (diff) | |
download | cython-15ce8b91510117c2a25e08659c33ee3966d5131c.tar.gz |
Fix compiler crash when analysing a complex name as a type using sizeof(X) translation. Requires type analysis before the "arg_type" is set.
Closes #1908.
-rw-r--r-- | Cython/Compiler/ExprNodes.py | 4 | ||||
-rw-r--r-- | tests/run/pure_pxd.srctree | 26 |
2 files changed, 26 insertions, 4 deletions
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index fead0a4a5..666d0e91e 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -1372,7 +1372,9 @@ def _analyse_name_as_type(name, pos, env): else: sizeof_node = declaration.root.stats[0].expr if isinstance(sizeof_node, SizeofTypeNode): - return sizeof_node.arg_type.analyse_types(env) + sizeof_node = sizeof_node.analyse_types(env) + if isinstance(sizeof_node, SizeofTypeNode): + return sizeof_node.arg_type return None diff --git a/tests/run/pure_pxd.srctree b/tests/run/pure_pxd.srctree index e50bce0c2..4e290dff5 100644 --- a/tests/run/pure_pxd.srctree +++ b/tests/run/pure_pxd.srctree @@ -1,5 +1,5 @@ PYTHON setup.py build_ext --inplace -PYTHON -c "import a; a.test()" +PYTHON -c "import a; a.test(a)" ######## setup.py ######## @@ -37,6 +37,18 @@ class ExtTypeAttributes(object): self.b = [1, 2, 3] +class TypedMethod(): + """ + >>> t = TypedMethod() + >>> t.meth() + 0.0 + """ + def meth(self): + from array import array + x = array('d', [0.0]) + return x[0] + + def func(a, b, c): """ >>> func(1, 2, 3) @@ -45,7 +57,7 @@ def func(a, b, c): return a + b + c -def test(): +def test(module): import os.path assert not os.path.basename(__file__).endswith('.py'), __file__ assert not os.path.basename(__file__).endswith('.pyc'), __file__ @@ -57,11 +69,14 @@ def test(): assert '>>> ' in func.__doc__ import doctest - doctest.testmod(verbose=True) + result = doctest.testmod(module, verbose=True) + assert not result.failed, result.failed ######## a.pxd ######## +cimport cython + cdef class ExtTypePass: pass @@ -75,4 +90,9 @@ cdef class ExtTypeAttributes: cdef readonly list b +cdef class TypedMethod: + @cython.locals(x='double[:]') + cpdef meth(self) + + cpdef int func(x, int y, z) except? -1 # argument names should not matter, types should |