Skip to content

Emit native array return type for properties-of types in psalter - #14930

Merged
orklah merged 2 commits into
vimeo:masterfrom
lyn1dev:fix-14915-properties-of-return-type
Nov 25, 2026
Merged

orklah merged 2 commits into
vimeo:masterfrom
lyn1dev:fix-14915-properties-of-return-type

Conversation

@lyn1dev

@lyn1dev lyn1dev commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

psalter (--alter) writes properties-of<T> as a native return type instead of array, producing invalid PHP syntax.

Before

<?php
/**
 * @template T of object
 * @param T $o
 * @return properties-of<T>
 */
function p($o) { return []; }

/**
 * @template T of object
 * @param T $o
 */
function q($o): properties-of<T> { return p($o); }

After

function q($o): array { return p($o); }

Fixes #14915

AI was used to write this code.

When psalter (--alter) adds missing return types for functions returning
properties-of types, it previously emitted the docblock type name
(e.g. `properties-of<T>`) as the native PHP return type, producing
a PHP syntax error. Both TPropertiesOf and TTemplatePropertiesOf cannot be
fully expressed in PHP signatures and resolve to arrays at runtime, so their
toPhpString() should return 'array'.

Co-Authored-By: Gemini 3.8 Flash <[email protected]>
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged

Project Memory (MB) Wall (s) Issues Weighted (types) Taint Dead code
✅ laravel 1 761 68.9 $\color{gray}{\textsf{+1.1\%}}$ 25 749 52 529 743 0
✅ symfony 3 654 221.7 $\color{gray}{\textsf{-1.1\%}}$ 51 710 100 179 1 581 0
✅ doctrine-orm 383 14.7 $\color{gray}{\textsf{+1.4\%}}$ 3 369 5 845 0 0
✅ psl 622 16.8 $\color{gray}{\textsf{-0.8\%}}$ 1 301 5 154 1 0
✅ phpunit 432 22.9 1 590 2 403 18 0
✅ php-parser 228 14.8 $\color{gray}{\textsf{-1.3\%}}$ 17 034 21 097 0 0
✅ tempest 895 40.5 $\color{gray}{\textsf{+0.1\%}}$ 5 434 10 883 275 0
✅ amphp-amp 48 1.2 $\color{gray}{\textsf{+7.4\%}}$ 32 59 0 0
✅ webmozarts-assert 276 3.0 $\color{gray}{\textsf{-1.0\%}}$ 576 2 720 0 0
✅ guzzle-promises 47 1.1 $\color{gray}{\textsf{-1.8\%}}$ 152 415 2 0
✅ monolog 135 3.9 $\color{gray}{\textsf{+4.1\%}}$ 916 2 483 11 0
✅ drupal 4 801 274.9 98 140 169 334 575 0
✅ wordpress 2 029 203.8 $\color{gray}{\textsf{-0.1\%}}$ 143 451 678 147 505 1
Total 15 311 888.2 $\color{gray}{\textsf{-0.2\%}}$ 349 454 1 051 248 3 711 1
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 +10 % 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. Its wall time warns above +5 % (±5 % is noise); the other thresholds apply per project.
  • Profiling: when both sides support it, the measured runs use --debug-performance=PATH for the hot-files block, which adds the same small CPU and memory cost to both sides.
  • 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 a4ba6d3 · base 3ab8bae (merge-base) · workflow run

@orklah orklah left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lyn1dev! The fix is right: the new case fails on master and passes here, and nullable/union returns now get array|null / int|array too.

Self-analysis fails on the PR (Shepherd and macOS jobs):

src/Psalm/Type/Atomic/TPropertiesOf.php:101:21: MissingPureAnnotation: toPhpString could be marked @psalm-pure
src/Psalm/Type/Atomic/TTemplatePropertiesOf.php:57:21: MissingPureAnnotation: toPhpString could be marked @psalm-pure

Both methods now return a constant, so add the tag to their docblocks, as in TMixed::toPhpString():

    /**
     * @param  array<lowercase-string, string> $aliased_classes
     * @psalm-pure
     */

Optional: a nullable case would cover the union path too (return $b ? p($o) : null; → : array|null).

orklah added a commit to orklah/psalm that referenced this pull request Nov 25, 2026
@orklah orklah added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 25, 2026

@orklah orklah left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lyn1dev! I pushed the missing @psalm-pure tags and a nullable test case myself, as I had related changes to land right after this one.

@orklah
orklah merged commit 4465362 into vimeo:master Nov 25, 2026
72 of 73 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.

--alter writes properties-of<T> as a native return type (invalid PHP)

2 participants