(🐞) Overload matching fails when sub expression contains an unrelated error
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
from dataclasses import dataclass
from typing import Generic, _T as T, overload
@dataclass
class A(Generic[T]):
it: T
@overload
def foo(x: A[int]) -> int: ...
@overload
def foo(x: A[str]) -> str: ...
reveal_type(foo(A(str(1 + "")))) # int; expected str
I think that the solution would be to change the current logic in infer_overload_return_type to something like:
- infer the types of the argument expressions in the call site without the callabletype typecontext
- check each overload against the inferred types
- If the types of the expressions match the types of the arguments, then the overload is matched.
- check the call against the matching overload as normal to generate error messages
links ⛓
- super issue of #16025
- Related #16101
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading infer_overload_return_type and reproduce the provided example to observe how the unrelated expression error affects overload selection. Trace how argument expressions are inferred and how each overload is checked. Done means the example reveals str while preserving normal error reporting for genuinely invalid calls.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100