validate that overload implementation can return a valid value for each overload
the end goal of overload validation (before proper overload types are implemented), is to ensure that the impl can produce a value of each overload, and nothing extra. this is best when it's inferred, because otherwise:
@overload
def f(a: int) -> str: ...
@overload
def f(a: str) -> int: ...
def f(a) -> int | str:
return 1 # no error about signature 1
using constraints
@overload
def f(a: int) -> list[object]: ...
@overload
def f(a: str) -> int: ...
def f(a): # error: does not conform to overload 1, expect `list[object]` to be used as a constraint to infer correctly
return [1] if bool else 1
i'm not 100% sure how this is supposed to work if we have conflicting constraints, but this is the gist of what should happen
previous steps:
- #1503
- #179
What's the difference between this issue and #179?
What's the difference between this issue and #179?
that issue is inferring the types including the return type, this issue is to instead use the overload return types as constraints when inferring the return type from the impl body
with the goal of ensuring that the impl body can produce a value of each overload
#290?
yes, #290 would cover this, but that's not going to happen any time soon