summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorscoder <stefan_ml@behnel.de>2020-06-04 10:45:34 +0200
committerGitHub <noreply@github.com>2020-06-04 10:45:34 +0200
commit389ba104d11354782a0a0a6273d8230116c8b092 (patch)
tree43cd9b4a6f2f4a9587f80d89ed0f1e66894cdc5f
parent12c7237b60a651cd40c3f847facae201aa1e36ab (diff)
parentf808448f2a4493965703261ab5ae2c4743c118e8 (diff)
downloadcython-389ba104d11354782a0a0a6273d8230116c8b092.tar.gz
Fix a bug where "fused_to_specific" was applied too widely (GH-3654)
Fixes https://github.com/cython/cython/issues/3642
-rw-r--r--Cython/Compiler/Nodes.py2
-rw-r--r--tests/run/fused_types.pyx23
2 files changed, 23 insertions, 2 deletions
diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py
index da4738d03..92907dd9a 100644
--- a/Cython/Compiler/Nodes.py
+++ b/Cython/Compiler/Nodes.py
@@ -1032,8 +1032,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 649c4f074..823d22ace 100644
--- a/tests/run/fused_types.pyx
+++ b/tests/run/fused_types.pyx
@@ -484,3 +484,26 @@ def test_fused_in_check():
print(in_check_2(1.0, 2.0))
print(in_check_2[float, double](1.0, 2.0))
print(in_check_3[float](1.0))
+
+### see GH3642 - presence of cdef inside "unrelated" caused a type to be incorrectly inferred
+cdef unrelated(cython.floating x):
+ cdef cython.floating t = 1
+ return 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)