-
-
Notifications
You must be signed in to change notification settings - Fork 863
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
Nullability false positive on a complex condition #987
Comments
Probably the same problem as #966 but I'll leave this open for referring to this specific case. |
There are a whole bunch of similar logic tests in TypeAlgebraTest. Most, if not all, fail in PHPStan but I imagine it's not that hard to alter your engine for them to pass. Psalm doesn't deal with #966 well either, as its algebraic assertions don't cover comparisons between variables. |
I misread the example - this is more complex than #966 (#966 does not work because I broke something on dev-master, it works on 0.9.2). This will require something I now call "Dependent types". Because of their lack, PHPStan can't solve these examples either:
Therefore I'm postponing solving this to after the next release because it's a bigger topic. |
Yeah, supporting this is on an ongoing basis is non-trivial. It requires keeping track of the assertions made in previous expressions as well as current types. A year-old description of that process is here: https://medium.com/vimeo-engineering-blog/automated-type-inference-for-dynamically-typed-programs-6e79197e5420 |
Similar example https://phpstan.org/r/87a4b338-f3bb-466f-b1fc-cbd5eecc00b5 |
Seems like it works on latest version https://phpstan.org/r/622c3f59-0fd7-4442-b89e-356e25287fd6 |
@janedbal It doesn't, it just moved to level 8: https://phpstan.org/r/9cc9771c-0c03-412c-b186-7f99bac5120f |
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-29: Function hello() should return array<string> but returns array<string>|null.
+No errors |
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-12: Parameter #1 $c of method HelloWorld::foo() expects int, int|null given.
+No errors |
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. |
Code snippet that reproduces the problem
Expected output
The text was updated successfully, but these errors were encountered: