diff options
author | da-woods <dw-git@d-woods.co.uk> | 2020-05-31 12:21:57 +0100 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2020-06-04 12:23:35 +0200 |
commit | 2a6aa2ef824e3cf2217eb9524996f64f8954cebd (patch) | |
tree | 3c23c8495a80c73a010e39321a89b494bf775fad | |
parent | 22f62fe1cc2702db9ca8a59199faf0de65f4e666 (diff) | |
download | cython-2a6aa2ef824e3cf2217eb9524996f64f8954cebd.tar.gz |
Fix a bug where fused_to_specific was applied too widely
Fixes https://github.com/cython/cython/issues/3642
-rw-r--r-- | Cython/Compiler/Nodes.py | 2 | ||||
-rw-r--r-- | tests/run/fused_types.pyx | 23 |
2 files changed, 23 insertions, 2 deletions
diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 8bda3ffcb..d3e0590ea 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1023,8 +1023,6 @@ class CSimpleBaseTypeNode(CBaseTypeNode): if scope is None: # Maybe it's a cimport. scope = env.find_imported_module(self.module_path, self.pos) - if scope: - scope.fused_to_specific = env.fused_to_specific else: scope = env diff --git a/tests/run/fused_types.pyx b/tests/run/fused_types.pyx index f7493a79f..732ea5359 100644 --- a/tests/run/fused_types.pyx +++ b/tests/run/fused_types.pyx @@ -400,3 +400,26 @@ def test_composite(fused_composite x): return x else: return 2 * x + + +### see GH3642 - presence of cdef inside "unrelated" caused a type to be incorrectly inferred +cdef unrelated(cython.floating x): + cdef cython.floating t + +cdef handle_float(float* x): return 'float' + +cdef handle_double(double* x): return 'double' + +def convert_to_ptr(cython.floating x): + """ + >>> convert_to_ptr(1.0) + 'double' + >>> convert_to_ptr['double'](1.0) + 'double' + >>> convert_to_ptr['float'](1.0) + 'float' + """ + if cython.floating is float: + return handle_float(&x) + elif cython.floating is double: + return handle_double(&x) |