Skip to content

fix(properties): keep analysing after an invalid static property assignment - #14515

Merged
orklah merged 1 commit into
vimeo:masterfrom
jirkace:fix/14442-static-prop-assign-unreachable
Nov 23, 2026
Merged

orklah merged 1 commit into
vimeo:masterfrom
jirkace:fix/14442-static-prop-assign-unreachable

Conversation

@jirkace

@jirkace jirkace commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Code after an invalid or possibly invalid static property assignment is treated as unreachable, so nothing after it is analysed.

Before

<?php
final class S {
    public static int $x = 0;
}

function possiblyInvalid(int|float $v): void {
    S::$x = $v; // PossiblyInvalidPropertyAssignmentValue
    undefinedFunction1(); // no issue
}

After

    undefinedFunction1(); // UndefinedFunction

Fixes #14442

…gnment vimeo#14442

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

jirkace commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Behaviour change

  • After InvalidPropertyAssignmentValue / PossiblyInvalidPropertyAssignmentValue on a static property (S::$x = ..., also S::$l[] = ...), the rest of the function is analysed again: StaticPropertyAssignmentAnalyzer returned false (stop analysing) once the issue was accepted. It now leaves the assignment like the instance property analyzer does, so issues after such an assignment are now reported (and, as for instance properties, the assigned type is what a later read of the property sees).
  • Unchanged: the assignment issues themselves; suppressed issues behave as before.

Verified: PropertyTypeTest::testCodeAfterAnInvalidStaticPropertyAssignmentIsAnalyzed (exact issue list for the three cases) fails on master (no UndefinedFunction after the assignments) and passes here. Full self-analysis: no new issue (only 2 MixedArgument from my local revolt/event-loop v1.0.9, unrelated).

@github-actions

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: increased

Project Memory (MB) Wall (s) Issues Weighted (types) Taint
✅ laravel 1 751 94.9 $\color{gray}{\textsf{-0.1\%}}$ 25 908 53 462 682
✅ symfony 3 600 209.3 $\color{gray}{\textsf{+1.2\%}}$ 50 611 98 405 1 528
✅ doctrine-orm 381 13.0 $\color{gray}{\textsf{+2.6\%}}$ 3 481 6 143 0
✅ psl 617 16.9 $\color{gray}{\textsf{+2.6\%}}$ 1 375 5 615 1
✅ phpunit 455 13.5 $\color{gray}{\textsf{+0.5\%}}$ 1 731 3 410 18
✅ php-parser 226 9.2 $\color{gray}{\textsf{+1.9\%}}$ 17 132 21 025 0
✅ tempest 895 24.9 $\color{gray}{\textsf{+0.1\%}}$ 5 047 10 528 252
✅ amphp-amp 68 1.2 $\color{gray}{\textsf{-1.6\%}}$ 29 49 0
✅ webmozarts-assert 272 2.8 $\color{gray}{\textsf{+0.4\%}}$ 577 2 720 0
✅ guzzle-promises 44 1.0 $\color{gray}{\textsf{+1.0\%}}$ 155 434 2
✅ monolog 135 3.5 $\color{gray}{\textsf{+1.1\%}}$ 913 2 479 10
✅ drupal 4 844 $\color{gray}{\textsf{+0.1\%}}$ 234.0 $\color{gray}{\textsf{+0.8\%}}$ 97 684 $\color{red}{\textsf{+93}}$ $\color{gray}{\textsf{-0}}$ 169 427 $\color{red}{\textsf{+134}}$ 583
Total 13 288 624.2 $\color{gray}{\textsf{+0.9\%}}$ 204 643 $\color{red}{\textsf{+93}}$ $\color{gray}{\textsf{-0}}$ 373 697 $\color{red}{\textsf{+134}}$ 3 076
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.
✅ drupal: issues +93 −0

Memory 4 841 → 4 844 MB (+0.1 %) · Wall 232.2 → 234.0 s (+0.8 %)

Weighted 169 293 → 169 427 (+134, +0.08 %): L1 +86 · L2 +1 · L3 +2 · always +4

Issue type added removed
ArgumentTypeCoercion 1 0
MixedArgument 11 0
MixedArrayAccess 15 0
MixedArrayAssignment 27 0
MixedAssignment 19 0
MixedMethodCall 4 0
MixedOperand 10 0
PossiblyInvalidOperand 1 0
RedundantConditionGivenDocblockType 1 0
UndefinedClass 3 0
UndefinedDocblockClass 1 0

Added (93)

  • core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php:473 ArgumentTypeCoercion (error): Argument 1 of ReflectionClass::__construct expects class-string|object, but parent type string provided
  • core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php:490 UndefinedDocblockClass (error): Docblock-defined class, interface or enum named Doctrine\Common\Annotations\DocParser does not exist
  • core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php:492 UndefinedClass (error): Class, interface or enum named Doctrine\Common\Annotations\DocParser does not exist
  • core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php:511 MixedArrayAssignment (error): Cannot access array value on mixed variable $metadata['properties'][$property->name]
  • core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php:531 UndefinedClass (error): Class, interface or enum named Doctrine\Common\Annotations\DocParser does not exist
  • core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php:533 UndefinedClass (error): Class, interface or enum named Doctrine\Common\Annotations\DocParser does not exist
  • core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php:533 MixedAssignment (error): Unable to determine the type that $annotation is being assigned to
  • core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php:538 MixedArrayAssignment (error): Cannot access array value on mixed variable $metadata['enum'][$property->name]
  • core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php:538 MixedArrayAssignment (error): Cannot access array value on mixed variable $metadata['enum'][$property->name]['value']
  • core/lib/Drupal/Component/Annotation/Doctrine/DocParser.php:539 MixedArrayAssignment (error): Cannot access array value on mixed variable $metadata['enum'][$property->name]
  • … and 83 more

head 5ecf98c · base c5f4dfd (merge-base) · workflow run

@jirkace

jirkace commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Review findings of the triage report (head 5ecf98c), checked:

  • Not reproduced: "after the assignment S::$x keeps its old narrowed type". In if (S::$x === 1) { S::$x = $float; }, a @psalm-trace S::$x after the assignment gives float, the assigned type, as the description says. Master gives no trace because it stops analysing there. Probe on this branch and on master.
  • The drupal +93: the sample I checked is the case this PR is about. In Component/Annotation/Doctrine/DocParser.php, private static $metadataParser is documented as \Doctrine\Common\Annotations\DocParser (the report also has UndefinedDocblockClass for it), and line 461 assigns new self(). Master stopped analysing the method at that assignment. Now the rest is analysed, and the issues that follow (UndefinedClass Doctrine\Common\Annotations\DocParser, MixedArrayAssignment on $metadata[...], ...) come from that wrong docblock type. I did not check all 93 lines.
  • Not changed, minor: the test asserts the issue list only, not the property type after the assignment.

No code change in this round. Not run: the full suite (CI runs it).

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

orklah commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Thanks @jirkace!

@orklah
orklah merged commit 515e42f into vimeo:master Nov 23, 2026
73 of 74 checks passed
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.

Code after possibly invalid static property assignment is treated as unreachable

2 participants