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

Property (-1|int<1, max>) does not accept int #6174

Closed
acelaya opened this issue Dec 8, 2021 · 10 comments
Closed

Property (-1|int<1, max>) does not accept int #6174

acelaya opened this issue Dec 8, 2021 · 10 comments
Labels
Milestone

Comments

@acelaya
Copy link
Sponsor

acelaya commented Dec 8, 2021

Bug report

I have a property annotated as @var positive-int|-1, but even if I explicitly check that the value to be assigned actually fulfils that (< 0 || === -1), PHPStan keeps reporting it cannot assign int to (-1|int<1, max>).

Code snippet that reproduces the problem

https://phpstan.org/r/22add73c-2fd7-45a1-a5b3-2e1ddb8a1847

Expected output

PHPStan should not throw an error

Did PHPStan help you today? Did it make you happy in any way?

PHPStan always helps. It's just amazing 🙂

@herndlm
Copy link
Contributor

herndlm commented Dec 8, 2021

Fyi the base problem seems to be the || that it apparently does not understand, see https://phpstan.org/r/019dca66-148c-483e-8e5c-f62ab1b5834e

@ondrejmirtes
Copy link
Member

@herndlm Yes, line 20 in your example should be -1|int<1, max>.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Feb 1, 2022
@acelaya
Copy link
Sponsor Author

acelaya commented Feb 1, 2022

@ondrejmirtes
Copy link
Member

Yeah, it's not fixed (I didn't say it is.)

@acelaya
Copy link
Sponsor Author

acelaya commented Feb 1, 2022

Oh, sorry, haha.

@phpstan-bot
Copy link
Contributor

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

@@ @@
-13: Property HelloWorld::$myValue (-1|int<1, max>) does not accept int.
+No errors

@phpstan-bot
Copy link
Contributor

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

@@ @@
 14: Dumped type: -1
 17: Dumped type: int<1, max>
-20: Dumped type: int
-22: Property HelloWorld::$myValue (-1|int<1, max>) does not accept int.
+20: Dumped type: -1|int<1, max>
Full report
Line Error
14 Dumped type: -1
17 Dumped type: int<1, max>
20 `Dumped type: -1

@phpstan-bot
Copy link
Contributor

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

@@ @@
-13: Property HelloWorld::$myValue (-1|int<1, max>) does not accept int.
+No errors

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@68e6443

@github-actions
Copy link

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 Mar 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants