Repository navigation
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
reportIgnoresWithoutCommentsenabled:cd e2e/result-cache-trait-ignore ../../bin/phpstan analyse --no-progress --error-format raw -vvv ../../bin/phpstan analyse --no-progress --error-format raw -vvvWith 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.unmatchedLineandignore.unmatchedIdentifieris unchanged.