Repository navigation
Resolve template types of method calls on a concrete generic static return type #6695
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
pawell67
wants to merge
4
commits into
phpstan:2.3.x
Choose a base branch
from
pawell67:fix-static-generic-concrete-arguments
base: 2.3.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.
+128
−16
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8fb4073
Resolve template types of method calls on a concrete generic static r…
pawell67 036744f
Port the generic static return type resolution to the turbo extension
pawell67 ab4aa8a
Bump expected turbo version
pawell67 befece6
Test the non-parse exception that stops the result cache save with a …
SanderMuller 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| parameters: | ||
| level: 8 | ||
| tmpDir: tmp | ||
| paths: | ||
| - src | ||
|
|
||
| rules: | ||
| - ResultCacheE2EInternalError\ClassNotFoundRule |
27 changes: 27 additions & 0 deletions
27
e2e/result-cache-internal-error/rule/ClassNotFoundRule.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,27 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace ResultCacheE2EInternalError; | ||
|
|
||
| use PhpParser\Node; | ||
| use PhpParser\Node\Stmt\Function_; | ||
| use PHPStan\Analyser\Scope; | ||
| use PHPStan\Broker\ClassNotFoundException; | ||
| use PHPStan\Rules\Rule; | ||
|
|
||
| /** | ||
| * @implements Rule<Function_> | ||
| */ | ||
| final class ClassNotFoundRule implements Rule | ||
| { | ||
|
|
||
| public function getNodeType(): string | ||
| { | ||
| return Function_::class; | ||
| } | ||
|
|
||
| public function processNode(Node $node, Scope $scope): array | ||
| { | ||
| throw new ClassNotFoundException('ResultCacheE2EInternalError\Missing'); | ||
| } | ||
|
|
||
| } |
This file was deleted.
Oops, something went wrong.
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
49 changes: 49 additions & 0 deletions
49
tests/PHPStan/Analyser/nsrt/generic-static-concrete-arguments.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,49 @@ | ||
| <?php declare(strict_types = 1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ondrej talks about his expectations in phpstan/phpstan#12680 (comment) we should assert these in a separate test |
||
|
|
||
| namespace GenericStaticConcreteArguments; | ||
|
|
||
| use function PHPStan\Testing\assertType; | ||
|
|
||
| /** | ||
| * @template TKey of array-key | ||
| * @template TValue | ||
| */ | ||
| class Box | ||
| { | ||
|
|
||
| /** @return static<int, string> */ | ||
| public function concrete() | ||
| { | ||
| return new static(); | ||
| } | ||
|
|
||
| /** @return static<int, TValue> */ | ||
| public function withTemplate() | ||
| { | ||
| return new static(); | ||
| } | ||
|
|
||
| /** @return array<TKey, TValue> */ | ||
| public function all(): array | ||
| { | ||
| return []; | ||
| } | ||
|
|
||
| /** @return TValue */ | ||
| public function first() | ||
| { | ||
| return 1; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * @param Box<string, bool> $box | ||
| */ | ||
| function test(Box $box): void | ||
| { | ||
| assertType('GenericStaticConcreteArguments\Box<int, string>', $box->concrete()); | ||
| assertType('array<int, string>', $box->concrete()->all()); | ||
| assertType('string', $box->concrete()->first()); | ||
| assertType('array<int, bool>', $box->withTemplate()->all()); | ||
| } | ||
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
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.
why do we need to adjust this tests expectations?