-
Notifications
You must be signed in to change notification settings - Fork 589
Fix false positive comparing identical generic types below level 8 #6392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
calebdw
wants to merge
1
commit into
phpstan:2.2.x
Choose a base branch
from
calebdw:calebdw/push-vquvsktlxvyr
base: 2.2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+101
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
57 changes: 57 additions & 0 deletions
57
tests/PHPStan/Rules/Methods/data/generic-argument-nullability.php
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace GenericArgumentNullability; | ||
|
|
||
| /** | ||
| * @template TKey of array-key | ||
| * @template TValue | ||
| */ | ||
| class Collection | ||
| { | ||
|
|
||
| } | ||
|
|
||
| class Foo | ||
| { | ||
|
|
||
| /** | ||
| * @template T | ||
| * @param callable(): T $cb | ||
| * @return T | ||
| */ | ||
| public function grab(callable $cb) | ||
| { | ||
| return $cb(); | ||
| } | ||
|
|
||
| /** | ||
| * @template T | ||
| * @param callable(mixed, array<string, mixed>): T $cb | ||
| * @return T | ||
| */ | ||
| public function grabTwoArgs(callable $cb) | ||
| { | ||
| return $cb(null, []); | ||
| } | ||
|
|
||
| /** @param Collection<string, int|null> $collection */ | ||
| public function acceptNullable(Collection $collection): void | ||
| { | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * @param Collection<string, int> $plain | ||
| * @param Collection<string, int|null> $nullable | ||
| * @param array<string, int|null> $array | ||
| */ | ||
| function test(Foo $foo, Collection $plain, Collection $nullable, array $array, ?int $scalar): void | ||
| { | ||
| $foo->grab(fn () => $plain); | ||
| $foo->grab(fn () => $nullable); | ||
| $foo->grab(fn () => $array); | ||
| $foo->grab(fn () => $scalar); | ||
| $foo->grabTwoArgs(fn () => $nullable); | ||
| $foo->acceptNullable($nullable); | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks promising but I don't think it's that easy.
Currently when you have
@template-covariantand you're trying to passFoo<int|null>intoFoo<int>below level 8, it doesn't report an error.But on the other hand, what we're trying to fix is passing
@template(invariant)Foo<int|null>intoFoo<int|null>below level 8, it SHOULD NOT report an error.And also, passing
Foo<int>intoFoo<int|null>should not be allowed for@templatebelow level 8.Please verify my statements, I'm not sure all of that is still true. And on which levels these start or stop being reported.
That's why in our experiments we were trying to solve it with this #4210