Repository navigation
Don't take matching another pattern for a paradox - #14444
Conversation
A pattern assertion only holds the taints its pattern removes, the same for another pattern removing the same taints: like in_array() assertions, it can't tell that a condition contradicts an earlier one. Fixes vimeo#14443
orklah
left a comment
There was a problem hiding this comment.
Thanks! The test fails on master with the ParadoxicalCondition of #14443 and passes here.
The same equality of MatchesPattern assertions still reaches the other place that compares clauses by value: the hash check of AlgebraAnalyzer::checkForParadox(), which skips InArray/NotInArray through hasInArrayPossibility() but not MatchesPattern. So this still reports a false RedundantCondition (also new in 7.13):
function f(string $v): int {
if (preg_match('/^a\((.+)\)$/s', $v) && preg_match('/^b\((.+)\)$/s', $v)) { // RedundantCondition: $v is matches-pattern-8388608 has already been asserted
return 1;
}
return 0;
}
Could you handle MatchesPattern there too (ideally one helper used by both findImplication() and checkForParadox(), with the comment on it, e.g. "these assertions don't say which pattern or array they were made from: two equal ones are not the same condition"), and add this snippet as a TypeAlgebraTest valid case?
✅ Performance: unchanged · Types: decreased
How to read this table
✅ symfony: issues +0 −6Memory 3 600 → 3 600 MB (<0.1 %) · Wall 207.2 → 209.6 s (+1.1 %) Weighted 98 502 → 98 448 (−54, −0.05 %): L4 −1 · always −5
Removed (6)
head 99542c1 · base cd22a51 (merge-base) · workflow run |
Like in-array assertions, a MatchesPattern assertion doesn't say which pattern it was made from, so the hash check of checkForParadox() reported a RedundantCondition for two different patterns that remove the same taints. One helper now skips these assertions in checkForParadox() and findImplication().
|
Thanks! Done in 99542c1: The same The same pattern twice ( |
Matching another pattern after a failed match
Psalm reports a false
ParadoxicalConditionfor apreg_match()on a value that already failed another pattern removing the same taints.Before
After
Matching two patterns
Psalm reports a false
RedundantConditionfor twopreg_match()calls with different patterns that remove the same taints.Before
After
Fixes #14443.