Skip to content

fix(context): a variable first assigned in a possibly skipped branch keeps its type - #14376

Merged
orklah merged 3 commits into
vimeo:masterfrom
jirkace:fix/13995-possibly-skipped-new-var
Nov 21, 2026
Merged

orklah merged 3 commits into
vimeo:masterfrom
jirkace:fix/13995-possibly-skipped-new-var

Conversation

@jirkace

@jirkace jirkace commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

A variable first assigned in the right operand of && loses its type outside an if condition: it is reported as undefined and typed mixed, although it is only possibly undefined.

Before

$matches = $enabled && check($captured = "b");
// $captured: no type (UndefinedVariable, MixedArgument where it is used)

After

$matches = $enabled && check($captured = "b");
// $captured: 'b' (PossiblyUndefinedVariable where it is used)

The same applies to a variable assigned in the possibly skipped operand of any && outside a condition; the || form is not covered.

Fixes #13995

…keeps its type vimeo#13995

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@jirkace

jirkace commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Behaviour change

  • A variable first assigned in the right operand of && outside an if condition now has its type, with possibly_undefined (PossiblyUndefinedVariable where it is used instead of an untyped variable reported as UndefinedVariable and MixedArgument). The change is in Context::mergeChangesOfPossiblySkippedBranch, which IfConditionalAnalyzer also calls; I did not measure its effect there beyond the tests of the PR.
  • Not covered: the same assignment in the right operand of || (still untyped).
  • Not run: the full suite (CI); benchmark corpora.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: decreased

Project Memory (MB) Wall (s) Issues Weighted (types) Taint
✅ laravel 1 765 73.7 $\color{gray}{\textsf{+0.1\%}}$ 26 014 $\color{gray}{\textsf{+0}}$ $\color{green}{\textsf{-1}}$ 53 211 $\color{green}{\textsf{-1}}$ 673
✅ symfony 3 605 259.1 $\color{gray}{\textsf{+1.0\%}}$ 50 678 $\color{red}{\textsf{+12}}$ $\color{green}{\textsf{-33}}$ 98 709 $\color{green}{\textsf{-7}}$ 1 491
✅ doctrine-orm 393 21.6 $\color{gray}{\textsf{+0.1\%}}$ 3 480 6 161 0
✅ psl 632 26.3 $\color{gray}{\textsf{-0.4\%}}$ 1 300 5 456 1
✅ phpunit 471 11.8 $\color{gray}{\textsf{-2.2\%}}$ 1 744 3 459 18
✅ php-parser 236 8.2 $\color{gray}{\textsf{+1.7\%}}$ 17 133 21 035 0
✅ tempest 903 21.4 $\color{gray}{\textsf{-0.4\%}}$ 5 042 10 514 242
✅ amphp-amp 61 2.4 $\color{gray}{\textsf{-1.2\%}}$ 29 49 0
✅ webmozarts-assert 286 5.5 $\color{gray}{\textsf{+1.3\%}}$ 577 2 722 0
✅ guzzle-promises 55 2.4 158 435 2
✅ monolog 153 6.8 $\color{gray}{\textsf{-2.9\%}}$ 903 2 403 10
✅ drupal 4 850 250.0 $\color{gray}{\textsf{+3.3\%}}$ 97 577 $\color{red}{\textsf{+1}}$ $\color{green}{\textsf{-2}}$ 169 326 $\color{green}{\textsf{-1}}$ 568
Total 13 413 689.1 $\color{gray}{\textsf{+1.5\%}}$ 204 635 $\color{red}{\textsf{+13}}$ $\color{green}{\textsf{-36}}$ 373 480 $\color{green}{\textsf{-9}}$ 3 005
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.
✅ laravel: issues +0 −1

Memory 1 765 → 1 765 MB (+0.0 %) · Wall 73.6 → 73.7 s (+0.1 %)

Weighted 53 212 → 53 211 (−1, <0.01 %): L1 −1

Issue type added removed
MixedAssignment 0 1

Removed (1)

  • src/Illuminate/Foundation/Cloud/Queue.php:264 MixedAssignment (error): Unable to determine the type that $messageId is being assigned to
✅ symfony: issues +12 −33

Memory 3 605 → 3 605 MB (<0.1 %) · Wall 256.6 → 259.1 s (+1.0 %)

Weighted 98 716 → 98 709 (−7, −0.01 %): L1 −30 · L2 +4 · L3 +5

Issue type added removed
DeprecatedMethod 4 0
MixedArgument 0 13
MixedArrayAccess 0 1
MixedAssignment 0 4
MixedMethodCall 0 10
MixedOperand 0 4
PossiblyInvalidArgument 0 1
PossiblyNullArgument 6 0
PossiblyNullOperand 2 0

Added (12)

  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:353 PossiblyNullArgument (error): Argument 1 of Symfony\Component\DependencyInjection\Dumper\XmlDumper::encode cannot be null, possibly null value provided
  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:355 PossiblyNullArgument (error): Argument 3 of preg_replace cannot be null, possibly null value provided
  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:355 PossiblyNullArgument (error): Argument 1 of ucwords cannot be null, possibly null value provided
  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:357 DeprecatedMethod (error): The method Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument::getDefaultIndexMethod has been marked as deprecated
  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:358 PossiblyNullArgument (error): Argument 1 of Symfony\Component\DependencyInjection\Dumper\XmlDumper::encode cannot be null, possibly null value provided
  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:358 DeprecatedMethod (error): The method Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument::getDefaultIndexMethod has been marked as deprecated
  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:360 DeprecatedMethod (error): The method Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument::getDefaultPriorityMethod has been marked as deprecated
  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:361 PossiblyNullArgument (error): Argument 1 of Symfony\Component\DependencyInjection\Dumper\XmlDumper::encode cannot be null, possibly null value provided
  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:361 DeprecatedMethod (error): The method Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument::getDefaultPriorityMethod has been marked as deprecated
  • src/Symfony/Component/Emoji/EmojiTransliterator.php:177 PossiblyNullArgument (error): Argument 3 of strpos cannot be null, possibly null value provided
  • … and 2 more

Removed (33)

  • src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php:2025 MixedArgument (error): Argument 1 of reset cannot be mixed, expecting array<array-key, mixed>
  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:350 MixedArgument (error): Argument 1 of Symfony\Component\DependencyInjection\Dumper\XmlDumper::encode cannot be mixed, expecting string
  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:350 MixedMethodCall (error): Cannot determine the type of $tag when calling method getTag
  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:352 MixedMethodCall (error): Cannot determine the type of $tag when calling method getIndexAttribute
  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:353 MixedArgument (error): Argument 1 of Symfony\Component\DependencyInjection\Dumper\XmlDumper::encode cannot be mixed, expecting string
  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:353 MixedMethodCall (error): Cannot determine the type of $tag when calling method getIndexAttribute
  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:355 MixedArgument (error): Argument 3 of preg_replace cannot be mixed, expecting array<array-key, float|int|string>|string
  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:355 MixedMethodCall (error): Cannot determine the type of $tag when calling method getIndexAttribute
  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:355 PossiblyInvalidArgument (error): Argument 1 of ucwords expects string, but possibly different type array<array-key, string>|null|string provided
  • src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php:357 MixedMethodCall (error): Cannot determine the type of $tag when calling method getDefaultIndexMethod
  • … and 23 more
✅ drupal: issues +1 −2

Memory 4 850 → 4 850 MB (<0.1 %) · Wall 242.1 → 250.0 s (+3.3 %)

Weighted 169 327 → 169 326 (−1, <0.01 %): L1 −1

Issue type added removed
MixedArgument 1 2

Added (1)

  • core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php:147 MixedArgument (error): Argument 1 of Drupal\Core\Routing\AdminContext::isAdminRoute cannot be Symfony\Component\Routing\Route|mixed|null, expecting Symfony\Component\Routing\Route|null

Removed (2)

  • core/modules/jsonapi/src/Controller/EntityResource.php:1375 MixedArgument (error): Argument 5 of Drupal\jsonapi\Controller\EntityResource::getPagerQueries cannot be non-empty-mixed, expecting int
  • core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php:147 MixedArgument (error): Argument 1 of Drupal\Core\Routing\AdminContext::isAdminRoute cannot be mixed, expecting Symfony\Component\Routing\Route|null

head d2b3ae2 · base 78d192b (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 merged commit d27ab58 into vimeo:master Nov 21, 2026
69 of 70 checks passed
@orklah

orklah commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

Thanks @jirkace!

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 the right operand of && loses its type outside an if condition

2 participants