Skip to content

Keep what both operands of xor assign in an if condition - #14357

Merged
orklah merged 1 commit into
vimeo:masterfrom
shu-chen-dot-ca:fix-13843-xor-assignment
Nov 21, 2026
Merged

orklah merged 1 commit into
vimeo:masterfrom
shu-chen-dot-ca:fix-13843-xor-assignment

Conversation

@shu-chen-dot-ca

Copy link
Copy Markdown
Contributor

Assignment in an operand of xor

A variable assigned in the right operand of xor in an if, elseif or ternary condition is undefined in the body, as if the operand could be skipped like the right side of ||.

Before

<?php
function f(?string $s, bool $c): void {
    if ($c xor ($t = $s) !== null) {
        /** @psalm-check-type-exact $t = string|null */
        echo $t; // UndefinedVariable, MixedArgument
    }
}

After

        echo $t; // no issue

Narrowing after an if on xor that leaves

After an if whose body always leaves, each operand of a xor condition is taken as false, as for ||.

Before

<?php
function f(?string $s, bool $c): void {
    if ($c xor ($t = $s) !== null) {
        return;
    }

    /** @psalm-check-type-exact $t = string|null */ // CheckType: $t = null
}

After

    /** @psalm-check-type-exact $t = string|null */ // no issue
Before After
before after

Fixes #13843

@github-actions

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged

Project Memory (MB) Wall (s) Issues Weighted (types) Taint
✅ laravel 1 765 72.7 $\color{gray}{\textsf{+0.3\%}}$ 25 920 53 212 578
✅ symfony 3 604 198.3 $\color{gray}{\textsf{-5.3\%}}$ 50 651 98 716 1 443
✅ doctrine-orm 393 19.0 $\color{gray}{\textsf{+0.1\%}}$ 3 480 6 161 0
✅ psl 632 23.0 $\color{gray}{\textsf{+1.2\%}}$ 1 300 5 456 1
✅ phpunit 471 20.2 $\color{gray}{\textsf{-1.1\%}}$ 1 743 3 459 17
✅ php-parser 236 13.8 $\color{gray}{\textsf{-0.2\%}}$ 17 133 21 035 0
✅ tempest 899 36.3 $\color{gray}{\textsf{+0.2\%}}$ 5 021 10 514 221
✅ amphp-amp 61 1.3 $\color{gray}{\textsf{-0.7\%}}$ 29 49 0
✅ webmozarts-assert 286 3.0 $\color{gray}{\textsf{-0.7\%}}$ 577 2 722 0
✅ guzzle-promises 55 1.3 158 435 2
✅ monolog 153 3.7 903 2 403 10
✅ drupal 4 852 239.3 $\color{gray}{\textsf{+0.6\%}}$ 97 555 169 327 545
Total 13 409 632.0 $\color{gray}{\textsf{-1.5\%}}$ 204 470 373 489 2 817
How to read this table
  • Memory: Psalm's own peak figure, threads=1. More than +5 % fails, unless the PR changes composer.json.
  • Wall: base and head run on the same runner; ±10 % is noise. Above +20 % warns, never fails. re-run: a reversed second run was taken and the faster kept.
  • Issues: head count over all categories, then $\color{red}{\textsf{+added}}$ $\color{green}{\textsf{-removed}}$ against base.
  • Weighted (types): type issues weighted by error level (levels 1–8 as is, always-errors 10, strictness checks 1). Taint and dead-code issues are not weighed. The projects' own code is pinned and their dependencies resolve identically for base and head, so a change means Psalm reports more, fewer or differently serious issues. A rise is not necessarily a regression.
  • Taint: head count of Tainted* issues, then $\color{orange}{\textsf{+added}}$ $\color{orange}{\textsf{-removed}}$ against base. Both are orange as either direction needs review: more can be new detection or false positives, fewer can be fixed false positives or lost detection.
  • Dead code: head count of unused-code issues, shown only when a run reported some (findUnusedCode). More is red, fewer is green.
  • Total: sum over the projects compared on both sides. Thresholds apply per project, not to the total.
  • Colors: $\color{red}{\textsf{red}}$ past a fail or warn threshold (or more issues), $\color{green}{\textsf{green}}$ an improvement past noise (or fewer issues), $\color{orange}{\textsf{orange}}$ needs review, $\color{gray}{\textsf{gray}}$ noise.
  • Performance: regressed if a head run crashed or timed out or a memory or wall delta is red, else improved if one is green, else unchanged. Its icon is the check result: ❌ fail · ⚠️ warn · ✅ pass; the icon next to each project is that project's result, 💥 = not comparable: base crashed or timed out (counts as ⚠️).
  • Types (heading): direction of the total weighted change, increased · decreased · unchanged. Taint and Dead code (heading): added and removed counts, present only when non-zero. Informational, never fails the check.

head b6d8993 · base f4609f6 (merge-base) · workflow run

@orklah orklah added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 21, 2026
@orklah

orklah commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

Thanks @shu-chen-dot-ca!

@orklah
orklah merged commit d0146d3 into vimeo:master Nov 21, 2026
72 of 73 checks passed
@shu-chen-dot-ca
shu-chen-dot-ca deleted the fix-13843-xor-assignment branch November 21, 2026 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:fix The PR will be included in 'Fixes' section of the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Variable assigned in an operand of xor is reported as UndefinedVariable

2 participants