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
Class constants using other constants are mixed #1551
Comments
I'm not familiar with how psalm implements this. One way to deal with this is to create a class to represent lazily loaded union type (with a closure that's called to resolve the value in the codebase), and only resolve the actual value of the union type the first time analysis needs to know the union type (which, most of the time, is after all of the classes are parsed)
|
Psalm sort of does this for class constants from other classes - when it can’t immediately infer the type it stores the node, then tries again in the constant population stage. |
This approach is suggested for issues such as the below (haven't tested these - this is just for an idea of what I mean)
<?php
class A {
const X = self::Y;
const Y = 3;
}
class C extends B {
}
const Z = C::X;
class B extends A {
const Z = self::X;
} |
This change introduces the TMixedDeferredConstant type, which marks a type as being a constant that needs to be resolved at a later stage. Fixes: vimeo#1551
This is great! Thanks for the hard work! |
The type of
Clazz::cons2
isint
, but Psalm infers it asmixed
.Example (https://psalm.dev/r/f479e3cc0a):
Example output:
If this is a hard problem, #942 should fix it.
The text was updated successfully, but these errors were encountered: