Skip to content

Fix flickering of trait errors deduplicated into the trait file#6071

Open
mabar wants to merge 2 commits into
phpstan:2.2.xfrom
mabar:trait-flicker-fix
Open

Fix flickering of trait errors deduplicated into the trait file#6071
mabar wants to merge 2 commits into
phpstan:2.2.xfrom
mabar:trait-flicker-fix

Conversation

@mabar

@mabar mabar commented Jul 21, 2026

Copy link
Copy Markdown

Possible fix for phpstan/phpstan#14932

When a constant-condition error inside a trait is deduplicated and reported "directly in the trait", the reported error invisibly carried the file path of one of the classes using the trait — and which class was picked depended on the run type (cold, warm, partial).

Symptoms:

With the proposed modifications, the error belongs to the trait file. Ignoring works by targeting the trait file's path, matches identically on every run, and survives adding or removing classes that use the trait. --generate-baseline writes the trait path as well.

The first commit makes the winner deterministic - fixes the run-to-run flicker on its own, but still attributes the error to the alphabetically last class that uses the trait.
The second makes the attribution independent of the set of using classes. BC break for single-use traits, but necessary for multiple uses. Baseline now matches behavior of the CLI output.

@ondrejmirtes

Copy link
Copy Markdown
Member

Do not modify existing test, add a new one instead please.

@mabar
mabar force-pushed the trait-flicker-fix branch from c8cecf8 to 038b4d1 Compare July 21, 2026 06:55
@mabar
mabar force-pushed the trait-flicker-fix branch from 038b4d1 to 339dcc0 Compare July 21, 2026 07:04
@mabar

mabar commented Jul 21, 2026

Copy link
Copy Markdown
Author

@ondrejmirtes Changed to be as close to original as possible, but I can't keep it identical because the test asserted the exact behavior this PR changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants