Substitute generic return types when the native hint is nullable#152
Open
MrSrsen wants to merge 1 commit into
Open
Substitute generic return types when the native hint is nullable#152MrSrsen wants to merge 1 commit into
MrSrsen wants to merge 1 commit into
Conversation
`should_override_type_typed` used `unwrap_nullable()`, which only strips the `?Foo` (Nullable) form and not the `Foo|null` (Union-with-null) form. A nullable-union native such as `object|null` therefore reached the union branch with its `null` member attached; since `object` and `null` are both scalar names, the branch judged the type unrefinable and discarded a generic docblock return like `@psalm-return ?T`, leaving the bare native. Use `non_null_type()` (strips null from both Nullable and Union forms) so the non-null part is analysed, matching the function's documented `Foo|null → Foo` intent. Fixes inherited generic returns such as Doctrine's `ServiceEntityRepository<T>::find(): ?T` resolving to `object|null`. Adds an assert_type regression fixture.
AJenbo
approved these changes
Jun 8, 2026
Author
|
@AJenbo I think CI won't pass unless you run the CI because my fork has no access to project secrets. Or, can I do something about the CI myself? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #151
should_override_type_typedusedunwrap_nullable(), which only strips the?Foo(Nullable) form and not theFoo|null(Union-with-null) form. A nullable-union native such asobject|nulltherefore reached the union branch with itsnullmember attached; sinceobjectandnullare both scalar names, the branch judged the type unrefinable and discarded a generic docblock return like@psalm-return ?T, leaving the bare native.Use
non_null_type()(strips null from both Nullable and Union forms) so the non-null part is analysed, matching the function's documentedFoo|null → Foointent. Fixes inherited generic returns such as Doctrine'sServiceEntityRepository<T>::find(): ?Tresolving toobject|null.Adds an assert_type regression fixture.