Pyre type fails because it assumes an incorrect return type R when we are returning T. It happens when we use a derived class in another class and access a field that is generic typed from the parent class.
Following is the toy code for which it is complaining at the last line.
T = TypeVar("T")
R = TypeVar("R")
@dataclass(frozen=True)
class A(Generic[T, R]):
t: T
r: R
class B(A[T, R]):
...
@dataclass(frozen=True)
class X(Generic[T, R]):
a: A[T, R]
b: B[T, R]
def getfromA(self) -> T:
return self.a.t
def getfromB(self) -> T:
# pyre-fixe[7] Incompatible return type [7]: Expected `Variable[T]` but got `Variable[R]`.Pyre
return self.b.t
Notice that it works correctly when using A, the base class with generic. But when using with B, the derived class, it inverts the types.
Am I missing something or am I hitting some known pyre bug?
Thanks