Skip to content

fix(traits): report an alias or precedence rule for a method the traits don't have - #14626

Merged
orklah merged 2 commits into
vimeo:masterfrom
jirkace:fix/8169-trait-adaptation-missing-method
Nov 23, 2026
Merged

orklah merged 2 commits into
vimeo:masterfrom
jirkace:fix/8169-trait-adaptation-missing-method

Conversation

@jirkace

@jirkace jirkace commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Psalm reports nothing for an alias, visibility change or precedence rule of a trait use that names a method the traits don't have, which PHP refuses with a fatal error.

Before

<?php
trait Greets {
    public function hello(): void {}
}

final class Greeter {
    use Greets {
        hi as greet; // no issue
    }
}

After

        hi as greet; // UndefinedMethod: An alias was defined for hi but this method does not exist

Fixes #8169

…ts don't have vimeo#8169

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

jirkace commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Behaviour change

  • New UndefinedMethod on a trait-use adaptation whose method none of the traits it applies to has (the named trait for T::m, all the traits of the use otherwise, methods of traits they use included), with PHP's own messages: An alias was defined for ..., The modifiers of the trait method ...() are changed, ..., A precedence rule was defined for .... PHP refuses all three at compile time.
  • Unchanged: adaptations of methods the traits have, nested traits included (new valid test); a trait that doesn't exist is still reported once, as UndefinedTrait.

Not run: the full test suite (CI runs it).

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit afcc9cb. Configure here.

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ Performance: unchanged · Types: unchanged

Project Memory (MB) Wall (s) Issues Weighted (types) Taint
✅ laravel 1 768 94.0 $\color{gray}{\textsf{+0.6\%}}$ 25 691 52 996 682
✅ symfony 3 596 205.0 $\color{gray}{\textsf{+2.8\%}}$ 50 610 98 403 1 528
✅ doctrine-orm 380 21.1 $\color{gray}{\textsf{+1.2\%}}$ 3 481 6 143 0
✅ psl 617 27.1 $\color{gray}{\textsf{+0.2\%}}$ 1 375 5 615 1
✅ phpunit 455 14.3 $\color{gray}{\textsf{-0.1\%}}$ 1 731 3 410 18
✅ php-parser 226 9.4 $\color{gray}{\textsf{-0.1\%}}$ 17 154 21 245 0
✅ tempest 895 26.6 $\color{gray}{\textsf{+0.1\%}}$ 5 047 10 528 252
✅ amphp-amp 45 1.4 $\color{gray}{\textsf{+0.7\%}}$ 29 49 0
✅ webmozarts-assert 272 $\color{gray}{\textsf{+0.1\%}}$ 4.2 $\color{gray}{\textsf{-1.2\%}}$ 577 2 720 0
✅ guzzle-promises 44 1.5 155 434 2
✅ monolog 135 5.3 $\color{gray}{\textsf{-1.3\%}}$ 913 2 479 10
✅ drupal 4 839 178.6 $\color{gray}{\textsf{-0.1\%}}$ 97 591 169 293 583
Total 13 273 588.4 $\color{gray}{\textsf{+1.1\%}}$ 204 354 373 315 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.

head 5f6d323 · base 9028ade (merge-base) · workflow run

…t be aliased vimeo#8169

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

jirkace commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

CI and review addition (new commit):

  • TraitTest::constant in trait with alias (use TraitA { PRIVATE_CONST as public PUBLIC_CONST; }) expected the code to be valid, but PHP rejects it: Fatal error: An alias (PUBLIC_CONST) was defined for method PRIVATE_CONST(), but this method does not exist (checked with php -r on 8.4; trait constants can't be aliased). It is now an invalid case expecting the new UndefinedMethod.
  • The check now looks at every trait of the adaptation before deciding (a trait that doesn't exist, which is reported as UndefinedTrait where it is used, may have had the method, so nothing more is reported then). New test aliasWithATraitThatDoesNotExist. The result is the same as before for the cases I could build; the loop is just clearer.

Ran the changed and new single cases and a full self-analysis: clean.

@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 ce3de35 into vimeo:master Nov 23, 2026
114 of 116 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.

False negative UndefinedMethod for trait method alias

2 participants