Skip to content

Failure to select specialization for union of non-final generic classes #1772

@sharkdp

Description

@sharkdp

We currently fail to select a useful specialization for the call to extract_t here:

class P[T]:
    x: T

class Q[T]:
    x: T

def extract_t[T](x: P[T] | Q[T]) -> T:
    raise NotImplementedError

reveal_type(extract_t(P[int]()))  # revealed: Unknown

https://play.ty.dev/f21605e1-a6d1-4b08-9f8c-c608fe0cbc22

Note that there is some ambiguity here, because of multiple inheritance. But we should still be able to solve for T. Note that it works fine if the classes are final: https://play.ty.dev/a3821fe3-ace6-402d-b257-b74f1fd74238

Metadata

Metadata

Assignees

Labels

genericsBugs or features relating to ty's generics implementation

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions