Commit 1b5b0a51 authored by da-woods's avatar da-woods

Potential fix for GH issue #3203

Gets the specialized type if possible from
NameNode.analyse_as_type

This does introduce a potential new bug:
```
cimport cython

just_float = cython.fused_type(float)

cdef OK1(just_float x):
    return just_float in floating

cdef fail1(just_float x, floating y):
    return just_float in floating

cdef fail2(floating x):
    return floating in floating

def show():
    """
    >>> show()
    True
    True
    True
    True
    """
    print(OK1(1.0))
    print(fail1(1.0, 2.0))
    print(fail1[float, double](1.0, 2.0))
    print(fail2[float](1.0))
```
fail1 and fail2 work before this patch but fail with it. It isn't
clear to me if this should actually be considered a bug. It
works in both versions with `cython.floating`, which possibly
suggests analyse_as_type in AttributeNode should also be changed
parent 758aaad0
......@@ -1961,6 +1961,12 @@ class NameNode(AtomicExprNode):
if not entry:
entry = env.lookup(self.name)
if entry and entry.is_type:
if entry.type.is_fused and env.fused_to_specific:
try:
return entry.type.specialize(env.fused_to_specific)
except KeyError:
pass # lots of valid reasons why we may not be able to get a specific type
# so don't fail
return entry.type
else:
return None
......
......@@ -2,6 +2,8 @@
cimport cython
from libcpp.vector cimport vector
from libcpp.typeinfo cimport type_info
from cython.operator cimport typeid
def test_cpp_specialization(cython.floating element):
"""
......@@ -14,3 +16,17 @@ def test_cpp_specialization(cython.floating element):
cdef vector[cython.floating] *v = new vector[cython.floating]()
v.push_back(element)
print cython.typeof(v), cython.typeof(element), v.at(0)
cdef fused C:
int
object
cdef const type_info* tidint = &typeid(int)
def typeid_call(C x):
"""
For GH issue 3203
>>> typeid_call(1)
True
"""
cdef const type_info* a = &typeid(C)
return a[0] == tidint[0]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment