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

Generics not typechecked #55

Closed
msullivan opened this issue May 23, 2018 · 5 comments
Closed

Generics not typechecked #55

msullivan opened this issue May 23, 2018 · 5 comments
Labels
enhancement Improvements and feature requests

Comments

@msullivan
Copy link

The following code passes typechecking:

# pyre-strict
from typing import TypeVar

T = TypeVar('T')
def coerce(x: T) -> int:
    1 + 'foo'
    return x

In general it seems that functions with types involving generics are not typechecked.

For comparison, mypy produces the following errors:

poly.py:6: error: Unsupported operand types for + ("int" and "str")
poly.py:7: error: Incompatible return value type (got "T", expected "int")
@dark
Copy link
Contributor

dark commented May 24, 2018

Yeah, that seems correct. --debug produces: Undefined type [11]: Type T is not defined.

@dkgi, any comment?

@dkgi
Copy link
Contributor

dkgi commented May 24, 2018

@sinancepel was looking into this recently.

@dkgi
Copy link
Contributor

dkgi commented May 24, 2018

Basically what happens here is that we try to figure out whether T <= int on the return statement and then give up because we do not store variables in the type order. We haven't yet really put much thought into surfacing these issues :|

@dark dark added the enhancement Improvements and feature requests label May 27, 2018
@oscarvarto
Copy link

Any further progress to support generics?

@mrkmndz
Copy link
Contributor

mrkmndz commented Apr 23, 2019

Over the course of the past few months we have done a lot of work on correctly supporting type variables. The given example as well as many many others now work correctly.

Please file new issues for any other type variable issues.

@mrkmndz mrkmndz closed this as completed Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements and feature requests
Projects
None yet
Development

No branches or pull requests

5 participants