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

fused type variable declared in unrelated function causes incorrect type inference #3642

Closed
anntzer opened this issue May 27, 2020 · 1 comment · Fixed by #3654
Closed

fused type variable declared in unrelated function causes incorrect type inference #3642

anntzer opened this issue May 27, 2020 · 1 comment · Fixed by #3654

Comments

@anntzer
Copy link
Contributor

anntzer commented May 27, 2020

The following example

cimport cython

cdef unrelated(cython.floating x):
    cdef cython.floating t

cdef handle_float(float* x): pass
cdef handle_double(double* x): pass

def main(cython.floating x):
    if cython.floating is float:
        handle_float(&x)
    elif cython.floating is double:
        handle_double(&x)

currently causes cython (both 0.29.19 and 3.0a5) to incorrectly (AFAICT) error out with

Error compiling Cython file:
------------------------------------------------------------
...

def main(cython.floating x):
    if cython.floating is float:
        handle_float(&x)
    elif cython.floating is double:
        handle_double(&x)
                     ^
------------------------------------------------------------

test.pyx:13:22: Cannot assign type 'float *' to 'double *'

Note that commenting out the cdef cython.floating t declaration removes the error, even though unrelated is never used by main.

@da-woods
Copy link
Contributor

I think (but could yet be wrong) that it's

scope.fused_to_specific = env.fused_to_specific

cythonscope is having the attribute fused_to_specific set on it, and that influences all subsequent lookups. Not sure right now how it should be fixed though.

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.

3 participants