Skip to content
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

infer non-empty-string on literal-string and strlen() #1260

Merged
merged 6 commits into from Apr 29, 2022

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Apr 28, 2022

No description provided.

@staabm staabm marked this pull request as ready for review April 28, 2022 07:59
@staabm staabm marked this pull request as draft April 28, 2022 08:02
@staabm
Copy link
Contributor Author

staabm commented Apr 28, 2022

memory related errors are also present on latest 1.6.x branch, therefore feel unrelated

@staabm staabm marked this pull request as ready for review April 28, 2022 08:44
@@ -235,9 +237,19 @@ public function specifyTypesInCondition(
$newContext = $newContext->negate();
}
$argType = $scope->getType($exprNode->getArgs()[0]->value);
if ($argType instanceof StringType) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

primary motivation was killing instanceof StringType checks

@staabm
Copy link
Contributor Author

staabm commented Apr 29, 2022

I am on holiday for a few days. Will investigate the webmozart/assert error after coming back...

@herndlm
Copy link
Contributor

herndlm commented Apr 29, 2022

You actually fixed something see comment in test file there ;) I overdid it with some of the tests..

@staabm
Copy link
Contributor Author

staabm commented Apr 29, 2022

Even better :-)

@staabm staabm marked this pull request as ready for review April 29, 2022 10:48
@ondrejmirtes
Copy link
Member

Just added a commit here: 2821732

The takeaway is - if something already is something, you don't need to tell TypeSpecifier to narrow it down again. So if you have strlen($literalString), TypeSpecifier doesn't need to say "add literal-string again".

@ondrejmirtes
Copy link
Member

So the useful thing is:

-						if ($argType instanceof StringType) {
+						if ($argType->isString()->yes()) {

Which is great and should be done in more relevant places.

@ondrejmirtes ondrejmirtes merged commit bc000e8 into phpstan:1.6.x Apr 29, 2022
@ondrejmirtes
Copy link
Member

Thank you.

@staabm staabm deleted the literal branch April 29, 2022 13:43
@staabm
Copy link
Contributor Author

staabm commented Apr 29, 2022

Which is great and should be done in more relevant places.

Yep, I am on it - after holiday :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants