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
Native types todos #8191
Comments
Good news: turns out the Composer project failure linked above wasn't really fault of native types but rather of this bug: phpstan/phpstan-src@8369197 So this feature isn't blocking PHPStan 1.9.0 release and we can work on it afterwards. |
Thank you for your descriptive information! Thank you for
I think this is a smart and explicit solution compared to phpstan/phpstan-src#1805. If my understanding is correct, should we promote Also some things to note
|
I brainstormed about this and realized we're stuck because of how things are currently organized. There's too much stuff and we'd have to duplicate all of it for native types:
We should clean it up first and then implement native types on top of a clean foundation. It follows an advice that always worked great for me: First make the change easy (refactor and clean up so future work is easier) and then make the easy change (once the foundation is prepared, it's much easier to implement it). And ideally do that with small, iterative and managable PRs with separate refactorings :) So what I propose to do first before we even think about native types is:
This is gonna be a lot of cleanup. But in the end the code will be much simpler. And we're definitely gonna learn a lot in the process :) So after these refactorings we're gonna end up with a single @rajyan I think you're definitely qualified for these refactorings so feel free to dive in, should be fun :) |
I remember we have discussed this before 👍 What I brain stormed at that time was, there might be a better data structure to handle these invalidation or we have to loop through all the expression types to invalidate them. |
Please note that the regex is an old way of doing invalidation and would only work for variables. The modern way is NodeFinder: https://github.com/phpstan/phpstan-src/blob/65f452d461cd7dbbbc8ff304b127fa2f95aedc46/src/Analyser/MutatingScope.php#L3676 Also note that we need to preserve methods like hasVariableType and getVariableType but since there's no longer be a separate storage for them, they simply need to construct new Variable node and ask a more general method. Same applies to assignVariable... |
BTW: As part of the |
Pulling current todos from comments around GitHub: Blocking:
Some inconsistencies in handling
And then:
|
I’m gonna address the first two blocking ones in tonight and tomorrow night. |
The Composer issue is reproduced in this simple snippet: https://phpstan.org/r/c875db3e-3640-4288-b9ff-92a6a13906cd |
Well, that was easy: phpstan/phpstan-src@bf1ef35 |
@ondrejmirtes After the latest push in 1.9.x, PHPStan now reports different result with your code snippet: @@ @@
-28: Expected native type mixed, actual: (int|string)
-29: Strict comparison using === between (int|string) and null will always evaluate to false.
-31: Expected native type null, actual: *NEVER*
-38: Expected native type mixed, actual: (int|string)
+38: Expected native type mixed, actual: mixed~null Full report
|
@ondrejmirtes |
This is almost done. Yeah, sure, some things could still be done but we don't need to keep this huge issue open :) |
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. |
Feature request
1.9.x is now pretty broken for projects with
treatPhpDocTypesAsCertain: false
: https://github.com/phpstan/phpstan/actions/runs/3297631860/jobs/5438715560This is because there's some work underway, but more needs to be done to fully implement it. From phpstan/phpstan-src#1802 I already merged some commits into 1.9.x: phpstan/phpstan-src@f097ca9...bf34e24
Before the rest of phpstan/phpstan-src#1802 is finished and merged, we have some work to do (in this order with no skipping):
$nativeExpressionTypes
property in MutatingScope, in favour of$variableNativeTypes
.$moreSpecificNativeTypes
to MutatingScope. The hard question is what to do about TypeSpecifier. We probably need to call it twice infilterByTruthyValue
/filterByFalseyValue
/filterBySpecifiedTypes
for complete and native types in order to have correct information.And on top of phpstan/phpstan-src#1802:
8f7bbf7
(#1802) and do it in a smarter way.MutatingScope::getNativeType()
should probably be implemented with a simple one-liner:return $this->promoteNativeTypes()->getType($node);
and for expressions where the implementation is different do an if-else based onbool $this->nativeTypesPromoted
. But most expressions will be the same.To remind, having
Scope::getNativeType()
to answer truthfully for all expressions will allow us to do some cool features:@var
is always wrong, because the thing on the right side of=
has a different type than what it's cast to.The text was updated successfully, but these errors were encountered: