Invalid overload implementation
We emit diagnostics for return types that are not assignable to the union of the overload return types.
The main issue that type checkers won't always pick up on is that the implementation return type can simply be object which everything is assignable to.
What gets flagged
| Python | |
|---|---|
1 2 3 4 5 6 7 8 | |
Unsoundness Checker Output
| Text Only | |
|---|---|
1 2 3 4 5 6 7 8 9 10 | |
Mypy: No Diagnostic Emitted
Pyright: No Diagnostic Emitted
Ty: No Diagnostic Emitted
A side note is that if you changed the return type of bar implementation to int | str, then most type checkers would catch this error.
What we can't catch
Due to more complex examples, we currently can't catch all invalid overload implementations.
The idea for the implementation of this was that at each return statement if all input variables had been narrowed to the types of the matching overload statement, then this would be a valid implementation.
Due to complex scenarios of lost information, we cannot make any assumptions about if this is valid or not.
| Python | |
|---|---|
1 2 3 4 5 6 7 8 | |
Unsoundness Checker: No Diagnostic Emitted
Mypy: No Diagnostic Emitted
Pyright: No Diagnostic Emitted
Ty: No Diagnostic Emitted
This is a more complex example which makes it very difficult to catch any errors. this is a valid implementation, but because we lost information about the use of x,
we cannot make any assumptions about if this is valid or not.
And because we don't want to emit false positives, we will not emit anything here.
| Python | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
Unsoundness Checker: No Diagnostic Emitted
Mypy: No Diagnostic Emitted
Pyright: No Diagnostic Emitted
Ty: No Diagnostic Emitted