Skip to content

Preserve trait ignore-comment errors in the result cache - #6883

Open
alfredbez wants to merge 2 commits into
phpstan:2.3.xfrom
alfredbez:fix/15177-trait-ignore-cache
Open

alfredbez wants to merge 2 commits into
phpstan:2.3.xfrom
alfredbez:fix/15177-trait-ignore-cache

Conversation

@alfredbez

Copy link
Copy Markdown
Contributor

With reportIgnoresWithoutComments: true, cached analysis drops errors about missing ignore comments in traits used by classes. The error count changes between runs. This change keeps those errors in the cache and preserves their trait context in editor mode.

Fixes phpstan/phpstan#15177

Reproducer: https://phpstan.org/r/2451c832-f6b7-45ae-8bdd-6c5733ac01b9
The playground shows the source example. To reproduce the cache behaviour, run the local fixture with reportIgnoresWithoutComments enabled:

cd e2e/result-cache-trait-ignore
../../bin/phpstan analyse --no-progress --error-format raw -vvv
../../bin/phpstan analyse --no-progress --error-format raw -vvv

With PHP 8.3.36 and the PHPStan 2.3.x source, the fixture reports 10 errors on the first run and 6 on the second. With this change, both runs report 10 and their output is identical. The test also checks editor mode and removes the trait from one class to check that its errors disappear while the other class's errors remain.

Not covered: Reporting of ignore.unmatchedLine and ignore.unmatchedIdentifier is unchanged.

…runs

When reportIgnoresWithoutComments is enabled, ignore.noComment and
ignore.allLineErrors emitted for code inside traits were created with
filePath set to the formatted file description instead of the analysed
class file, and traitFilePath set to null.

Because the result cache indexes errors by Error::getFilePath() and
restores cached errors only for analysed files on warm runs, contextual
ignore errors in traits were lost when restoring from cache.

Pass the analysed file path and the trait file path to Error in
FileAnalyser.
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.

reportIgnoresWithoutComments on Traits are skipped while cached

1 participant