-
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
Fix ClassConstFetch Identical specification with Yoda conditions #2498
Fix ClassConstFetch Identical specification with Yoda conditions #2498
Conversation
Hi, I'd be happier with NodeScopeResolverTest. We can leave the rule test but it'd be best to check the type inference (truthy/falsy context too). Thanks! |
ac0b40b
to
1250516
Compare
sure. added it. |
1250516
to
7ee61dd
Compare
public function testClass(TranslatableInterface $translatable): void | ||
{ | ||
if ($translatable::class !== TranslatableMessage::class) { | ||
assertType('Bug9542\TranslatableInterface~Bug9542\TranslatableMessage', $translatable); |
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.
There's a bad bug here. So you've eliminated that $translatable
isn't TranslatableMessage
. But it can still be a subclass of TranslatableMessage
.
Most likely we should only specify the type for $context->true()
.
Same thing is done for get_class
:
phpstan-src/src/Analyser/TypeSpecifier.php
Lines 194 to 210 in 2df1a59
if ( | |
$context->true() | |
&& $unwrappedLeftExpr instanceof FuncCall | |
&& $unwrappedLeftExpr->name instanceof Name | |
&& strtolower($unwrappedLeftExpr->name->toString()) === 'get_class' | |
&& isset($unwrappedLeftExpr->getArgs()[0]) | |
) { | |
if ($rightType->getClassStringObjectType()->isObject()->yes()) { | |
return $this->create( | |
$unwrappedLeftExpr->getArgs()[0]->value, | |
$rightType->getClassStringObjectType(), | |
$context, | |
false, | |
$scope, | |
$rootExpr, | |
)->unionWith($this->create($leftExpr, $rightType, $context, false, $scope, $rootExpr)); | |
} |
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.
could we be "smarter" if TranslatableMessage
is a reference to a final class (or a interface)?
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.
We could, but first we need to get rid of the bug, then we can improve it :)
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.
adapted. better? I didn't even notice this.. :)
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.
oh sorry, I was lazy and didn't run the full tests :/
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.
thx for the fix!
Avoids false positive inheritance types in false context
fe58422
to
446ee63
Compare
Closes phpstan/phpstan#9542
Is this how you would have done it? Might be the simplest way I guess. It's just an adapted version to handle the left/right mixed variant of the block directly before it.
UPDATE: I had the urge to somehow simplify/cleanup things, like the way left and right types are fetched from the scope, assigned to variables and used, in Identical in a follow-up but I failed. Better not touch it too much 😅