-
Notifications
You must be signed in to change notification settings - Fork 523
Introduce class_implements dynamic return type #2023
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
Conversation
34b5996
to
30b9603
Compare
This pull request has been marked as ready for review. |
The failing build seems legit. |
5fd344f
to
9c24a4e
Compare
9c24a4e
to
750bec2
Compare
I just checked the failing build for the integration builds and this is expected.
|
750bec2
to
6a3e0e3
Compare
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.
Also there are situations the function will always return false
. Which aren't covered here.
} | ||
|
||
$objectOrClassType = $scope->getType($functionCall->getArgs()[0]->value); | ||
$autoload = !isset($functionCall->getArgs()[1]) |
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.
$autoload
should be a TrinaryLogic. So you should do (new ConstantBooleanType(true))->isSuperTypeOf($secondArg)
. Because you might have true
(yes), bool
or mixed
(maybe), or false
(no).
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 ?
If I'm not sure that true
is passed, I cannot remove the false
return type.
So bool
, mixed
or false
(ie, maybe and no) are working the same way.
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.
Please test these scenarios.
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.
Tests added
$autoload = !isset($functionCall->getArgs()[1]) | ||
|| $scope->getType($functionCall->getArgs()[1]->value)->equals(new ConstantBooleanType(true)); | ||
|
||
if ($objectOrClassType instanceof UnionType) { |
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.
No reason to do instanceof *Type
here. A single $this->canFunctionReturnFalse($objectOrClassType, $autoload)
call should be sufficient.
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.
If I just write
if ($this->canFunctionReturnFalse($objectOrClassType, $autoload)) {
return null;
}
my tests are failing
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.
Nevermind, I found a way to do it.
Do you have examples ? How can I know that the class is not loaded ? |
@VincentLanglet A constant string that isn't a class. |
Done :) |
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.
I think the array values should be class-string in all cases.
I used I suspect that |
For this purpose it is. You can use more specific trait-string and interface-string which currently mean the same thing but in the future they might be different. |
Thanks for the precision ; I did the changes |
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.
Regression test please for 4335, based on the issue bot output.
Can you also please go through these failures and think about whether they're valid or not? Thanks.
Added
This is expected since the false check is not needed for PHPStan. This is expected too |
Thank you. |
1 similar comment
Thank you. |
Closes phpstan/phpstan#4335