Repository navigation
fix(algebra): a falsy variable holding a condition narrows to its negation - #14441
Conversation
…ation vimeo#14253 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Behaviour change A boolean variable assigned a condition ( Effects: fewer No existing test expectation was edited; the existing stored-condition cases I ran one by one pass ( Not run: the full PHPUnit suite (CI runs it). Run locally: the new test case on the branch (passes) and on master (fails), phpcs, full self-analysis. A corpus check follows. |
✅ Performance: unchanged · Types: decreased
How to read this table
✅ symfony: issues +0 −1Memory 3 600 → 3 600 MB (<0.1 %) · Wall 169.4 → 168.8 s (−0.4 %) Weighted 98 405 → 98 402 (−3, <0.01 %): L3 −1
Removed (1)
✅ doctrine-orm: issues +0 −1Memory 381 → 381 MB (<0.1 %) · Wall 21.1 → 21.0 s (−0.2 %) Weighted 6 143 → 6 142 (−1, −0.02 %): L1 −1
Removed (1)
✅ webmozarts-assert: issues +0 −2Memory 272 → 272 MB (<0.1 %) · Wall 4.7 → 4.8 s (+1.3 %) Weighted 2 720 → 2 714 (−6, −0.22 %): L3 −2
Removed (2)
head 47a7b2e · base c5f4dfd (merge-base) · workflow run |
…he variable is null vimeo#14253 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Behaviour change (follow-up) One existing test expectation changed in ae7ca78: $has = $b !== null;
if ($has || $c) {
echo 1;
} else {
echo $b->get(); // was PossiblyNullReference, now NullReference
}In the Corpus check (laravel and symfony sources, vs |
orklah
left a comment
There was a problem hiding this comment.
Thanks, the direction is right and the corpus removals are all fixed false positives. One problem with how the negation is built:
$right_clauses has already been through Context::filterClauses($var_id, ...), which drops the clauses that mention the assigned variable. Dropping a conjunct weakens the formula, which is fine for the truthy side, but it makes its negation stronger than what the code proves:
function selfRef(?Node $x, bool $ok): void {
$ok = $x !== null && $ok;
if (!$ok) {
if ($x !== null) { echo "reachable"; } // TypeDoesNotContainType on this PR, nothing on master
}
}Could you negate the unfiltered formula with FormulaGenerator::getNegatedFormula() (the helper the other negation sites use; it also handles assigning right sides and lossy negations), then filter the result? Something like:
$cond_clauses = $right_clauses; // before filterClauses()
// ...
Context::filterClauses(
$var_id,
FormulaGenerator::getNegatedFormula(
$cond_clauses,
$assign_value,
$cond_object_id,
$context->self,
$statements_analyzer,
$codebase,
),
),With that change the case above is clean and your two test cases still pass. Please add the selfRef case as a test.
…eo#14253 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@orklah thanks, done in 5a45872: the negation is now built from the unfiltered condition with Your |
A condition stored in a variable narrows only where the variable is truthy: where it is falsy (after
if ($flag) { return; }, inif (!$flag)or in theelse), the negation of the condition is not applied.Before
After
Fixes #14253