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

non-empty-string is not always truthy #5317

Closed
BackEndTea opened this issue Jul 16, 2021 · 12 comments · Fixed by phpstan/phpstan-src#1542
Closed

non-empty-string is not always truthy #5317

BackEndTea opened this issue Jul 16, 2021 · 12 comments · Fixed by phpstan/phpstan-src#1542
Labels

Comments

@BackEndTea
Copy link
Contributor

BackEndTea commented Jul 16, 2021

Bug report

if the length of a string is 1, it is not necessarily truthy. if it is '0', the string is fasly

Code snippet that reproduces the problem

https://phpstan.org/r/0d0ff87d-1142-4c8d-887a-9ea257c0540b
https://phpstan.org/r/af765852-8582-480e-8225-6457ee0b214e
https://3v4l.org/BeHAV

Expected output

No errors

@BackEndTea BackEndTea changed the title String with lenght of 1 is not always truthy non-empty-string is not always truthy Jul 16, 2021
@ondrejmirtes
Copy link
Member

Yeah, you're right, but I think we need to introduce another type, something like non-falsy-string, because there are examples of non-empty-string where we know if's not falsy either.

@ondrejmirtes
Copy link
Member

And it's useful to mark if ($is) as always-true if it's really the case.

@VincentLanglet
Copy link
Contributor

For the record, since https://github.com/vimeo/psalm/releases/tag/4.5.0, there is a non-falsy-string type in psalm.

@phpstan-bot
Copy link
Contributor

@BackEndTea After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-6: Dumped type: non-empty-string
-8: Negated boolean expression is always false.
+No errors

@phpstan-bot
Copy link
Contributor

@BackEndTea After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-8: Negated boolean expression is always false.
+No errors

@VincentLanglet
Copy link
Contributor

Seems fixed.
This can be closed @ondrejmirtes

@ondrejmirtes
Copy link
Member

It's not fixed, it was a bug in the playground.

@JTAjala
Copy link

JTAjala commented May 20, 2022

I currently have this issue with this
Is there a timeline when it will be fixed? The last activity on here was last year
image

the library I'm using is php-fig/http-message/StreamInterface.php eof()

@ondrejmirtes
Copy link
Member

@JTAjala your issue is most likely unrelated, please open a separate bug report

@voku
Copy link
Contributor

voku commented Jun 10, 2022

@staabm
Copy link
Contributor

staabm commented Jul 24, 2022

did some research on this topic.

in psalm non-falsy-string was initially implemented with vimeo/psalm@a0420fb

for phpstan-src inspiration:

staabm added a commit to staabm/phpstan-src that referenced this issue Jul 24, 2022
staabm added a commit to staabm/phpstan-src that referenced this issue Jul 24, 2022
staabm added a commit to staabm/phpstan-src that referenced this issue Jul 25, 2022
clxmstaab pushed a commit to staabm/phpstan-src that referenced this issue Jul 26, 2022
ondrejmirtes pushed a commit to staabm/phpstan-src that referenced this issue Jul 26, 2022
ondrejmirtes pushed a commit to staabm/phpstan-src that referenced this issue Aug 5, 2022
@github-actions
Copy link

github-actions bot commented Sep 6, 2022

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants