Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typeid failed on fused types #3203

Closed
thautwarm opened this issue Oct 23, 2019 · 2 comments · Fixed by #3205
Closed

typeid failed on fused types #3203

thautwarm opened this issue Oct 23, 2019 · 2 comments · Fixed by #3205

Comments

@thautwarm
Copy link

# cython: language=c++
# cython: language_level=3str
from libcpp.typeinfo cimport type_info
from cython.operator cimport typeid
cdef fused C: 
   int 
   object 
cdef const type_info* i32 = &typeid(int) 
cdef f(C x): 
    cdef const type_info* a = &typeid(C) 
    return a  == i32 
     
def g(x): 
   return (x, f(x)) 
da-woods added a commit to da-woods/cython that referenced this issue Oct 24, 2019
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
@scoder
Copy link
Contributor

scoder commented Oct 26, 2019

It's generally helpful in bug reports to also show the error message that results, as well as other relevant information, such as the code that was generated. Providing this information reduces the time that others need to plan to invest in order to investigate the issue. Basically, when I have limited time and an issue seems more costly to look into than what I currently can (or want to) invest, I look at other issues first.

@thautwarm
Copy link
Author

Okay, will do this

@scoder scoder added this to the 3.0 milestone Apr 18, 2020
scoder added a commit that referenced this issue Apr 18, 2020
* 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

* Bring attribute.fused types in line

* Removed try-catch

* Fix and test "type in fused_type" special-case

* Added "analyse_as_specialized_type"

* Fixed cpp_operators (handle type is None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants