Fix self type specialization in overloaded __init__ methods (#384)
Issue
Fixes #384
This PR addresses an issue with self type specialization in overloaded __init__ methods. The type checker was not properly handling specialized self types during constructor calls with generic classes.
Changes
- Modified
callable_inferincallable.rsto properly handle self type substitution for__init__method calls - Added detection for
__init__method calls with self arguments - Implemented proper self type substitution in return types using
subst_self_type_mut - Updated call handling to ensure correct type inference for constructor calls with specialized self types
- Integrated with typeshed stubs to ensure compatibility with standard library patterns
Testing
Verified with test cases in constructors_call_init.py, particularly those involving classes with overloaded __init__ methods that specify specialized self types (e.g., Class5[list[int]], Class5[set[str]]).
Impact
This fix ensures that when a class defines overloaded __init__ methods with specialized self types, the type checker correctly resolves constructor calls to the expected specialized type, improving type inference accuracy for generic class instantiation.
I would expect to see some conformance changes from fixing this issue, but I don't see conformance.exp changes - did you run test.py and commit the generated files?
Also, since this feature is tricky, please add integration tests here: https://github.com/facebook/pyrefly/blob/main/pyrefly/lib/test/overload.rs
Closing this PR due to inactivity. Feel free to reopen once you address the comments. Thanks!