-
Notifications
You must be signed in to change notification settings - Fork 504
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
Give class template context to conditional checker #2241
Conversation
a68edf9
to
f7f7f40
Compare
This pull request has been marked as ready for review. |
f7f7f40
to
7c3e695
Compare
@@ -0,0 +1,34 @@ | |||
<?php declare(strict_types = 1); | |||
|
|||
namespace Generics\Bug8609; |
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.
it seems you are adding a new test-case here, but you did not analyze this file from any of the *Test classes.
you need to make sure that this file is analyzed from the correct *Test class - the one which is testing the rule which emits the error you are trying to fix
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.
- File name needs to be in
bug-8609.php
format. - File needs to be analysed by tests/PHPStan/Rules/PhpDoc/MethodConditionalReturnTypeRuleTest.php.
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.
Additionally, we need to test that this actually works. A new file tested in NodeScopeResolverTest would be nice.
@@ -31,7 +31,12 @@ public function processNode(Node $node, Scope $scope): array | |||
return []; | |||
} | |||
|
|||
return $this->helper->check($variants[0]); | |||
$variant = $variants[0]; | |||
$templateTypeMap = $node->getClassReflection()->getTemplateTypeMap()->union( |
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.
union
isn't the best operation for this. I suggest array_merge
instead, like here:
phpstan-src/src/Analyser/NameScope.php
Lines 164 to 167 in b250a8b
new TemplateTypeMap(array_merge( | |
$this->templateTypeMap->getTypes(), | |
$map->getTypes(), | |
)), |
@@ -0,0 +1,34 @@ | |||
<?php declare(strict_types = 1); | |||
|
|||
namespace Generics\Bug8609; |
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.
- File name needs to be in
bug-8609.php
format. - File needs to be analysed by tests/PHPStan/Rules/PhpDoc/MethodConditionalReturnTypeRuleTest.php.
Finished it myself :) Thank you! |
This PR fixes bug reported here: phpstan/phpstan#8609