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
Refactor Reconciler::handleLiteralEquality #7304
Conversation
Note: the commit 72fd3de on master will most certainly be a conflict with this PR. It should not be too bad to resolve I think |
From a quick skim this all looks good. In my Rust-based fork I took the time to change string-based assertions to an enum (which in Psalm could be done with regular class inheritance) pub enum Assertion {
Any, // used for the null state
IsType(TAtomic),
IsNotType(TAtomic),
Falsy,
Truthy,
IsEqual(TAtomic),
IsNotEqual(TAtomic),
IsEqualIsset,
IsIsset,
IsNotIsset,
HasStringArrayAccess,
HasIntOrStringArrayAccess,
ArrayKeyExists,
ArrayKeyDoesNotExist,
InArray(TUnion),
NotInArray(TUnion),
HasArrayKey(String),
NonEmptyCountable(bool),
EmptyCountable,
HasExactCount(usize),
DoesNotHaveExactCount(usize),
} Psalm's version would need a couple more of these like |
Sorry for this one, it won't be easy to review.
There is multiple goals here, all intertwined:
has_int
but they did not match with know literals here: https://github.com/vimeo/psalm/pull/7287/files#diff-7ff683939a23ffc517c44a710a76bfa18959b516c0b77b6c27fb241bc748d83dR1332 so there were failures in some cases)$atomic instanceof TLiteralInt && $atomic->value === $assertion_value
. This is longer but infinitely more clear to read. We have a similar thing here: https://github.com/vimeo/psalm/pull/7287/files#diff-7ff683939a23ffc517c44a710a76bfa18959b516c0b77b6c27fb241bc748d83dR1388 where we just tweakfloat(5)
to fetch the "5" value.I wanted to keep a clear history of commits but this got out of control quickly. So I think I'll smash the majority of later commits together. I kept them for now for easier reading
I'll probably refactor the float case now that I started, to keep consistency. This has high chances of resolving some old bugs, but if I'm honest, it will probably create some (though they should be easier to fix). It will probably change some TypeDoesNotContainType into DocblockTypeContradiction or the other way around because I was more consistent with keeping the origin of the type than before.
I thought about pushing this on Psalm 5 instead, but I fear that if we do that, we'll have to move #7286, #7287 and #7288 too and I'm not sure if we should or if it's easy to do.
(My goal when I started those changes was to add
Reconciler::RECONCILIATION_*
in @param-out. If I knew I'd have to do all that, I may not have started!)