Repository navigation
Do not reuse name scopes built from the simplified AST for an analysed file - #6833
Merged
Merged
Conversation
…d file FileTypeMapper builds a file's name scopes from defaultAnalysisParser, which routes a file outside the analysed paths to the cleaning parser. Its AST has no function bodies, so the name scopes of classes declared inside them are missing. The ftm- cache entry was validated against the file contents only, so after a run on other paths a full run reused the incomplete map and the PHPDoc of such a class resolved to nothing, even with the result cache cleared. The entry now records for each file whether its AST was simplified and is reused only when that still holds, and the key tells the two kinds of entries of the main file apart so that partial and full runs do not evict each other. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012fzQU5nUgW3pCEZJonVBhv
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.
Closes phpstan/phpstan#15475
FileTypeMapperbuilds a file's name scopes fromdefaultAnalysisParser.PathRoutingParsersends a file outside the analysed paths to the cleaning parser, whose AST has no function bodies, so the name scopes of classes declared inside them (e.g. an anonymous class returned by a helper) are missing. Theftm-cache entry was validated against the file contents only. After a run on other paths, a full run reused the incomplete map, and the PHPDoc of such a class resolved to nothing, even afterclear-result-cache. It is the persistent-cache twin of #15231, where the in-memoryCachedParserwas moved behind the routing.PathRoutingParserextracts its routing decision intogetParser()and exposesreturnsSimplifiedAst();parseFile()behaves as before.ftm-entry records, for each file it was built from (including trait files), whether that file's AST was simplified, and is reused only if that still holds. The key also depends on whether the main file's AST is simplified, so partial and full runs keep separate entries instead of rebuilding each other's. Bumped tov8to drop existing entries.Name scopes keep being built from the same AST that BetterReflection reflects, and no file is parsed a second time: a vendor file's simplified AST still comes from the cache shared with BetterReflection. Building them always from the rich AST (#6739) would parse every non-analysed file again on a cold name-scope cache, put those ASTs into the analysed files' AST cache, and could pick a different class declaration than BetterReflection for code guarded by
PHP_VERSION_ID, which only the simplified AST removes.The e2e test
e2e/bug-15475uses the issue's files verbatim, withphpVersion: 80300for the anonymous readonly class. It runsanalyse src/usage.php,clear-result-cacheand a fullanalyse, in the E2E job (PHP 8.2) and in the Turbo arena job (PHP 8.5 with the extension). Verified locally in both setups (PHP 8.2 via Docker): the last run reports thereturn.typeerror without the fix and no errors with it.🤖 Generated with Claude Code
https://claude.ai/code/session_012fzQU5nUgW3pCEZJonVBhv