[6.x] Skip trait in getMethodMutations when storage is missing (fixes "Could not get class storage")#11789
Open
[6.x] Skip trait in getMethodMutations when storage is missing (fixes "Could not get class storage")#11789
getMethodMutations when storage is missing (fixes "Could not get class storage")#11789Conversation
… missing Demonstrates the crash in ClassLikeAnalyzer::getMethodMutations() when a trait is registered via reflection (present in existing_traits) but has no entry in ClassLikeStorageProvider::$storage. Real-world trigger: any Laravel class extending Illuminate\Console\Command, which uses the PromptsForMissingInput trait.
ClassLikeAnalyzer::getMethodMutations() iterates AST TraitUse nodes unconditionally, but a trait may be registered via reflection (present in existing_traits) without having an entry in ClassLikeStorageProvider::$storage. This causes an InvalidArgumentException crash with zero JSON output. Add a has() guard before accessing trait storage, matching the pattern used in the interface fix (03037f7). Real-world trigger: Laravel projects using Illuminate\Console\Command, which uses the PromptsForMissingInput trait. Any class extending Command with an uninitialized typed property triggers collect_initializations → getMethodMutations → crash. Relates to vimeo#11006, vimeo#9306, vimeo#8953
getMethodMutations when storage is missing (fixes "Could not get class storage")
getMethodMutations when storage is missing (fixes "Could not get class storage")getMethodMutations when storage is missing (fixes "Could not get class storage")
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.
Fixes #8953
Psalm 6.x crashes with
InvalidArgumentException: Could not get class storage for illuminate\console\concerns\promptsformissinginputwhen analyzing Laravel projects containing classes that extendIlluminate\Console\Command.Root cause:
ClassLikeAnalyzer::getMethodMutations()iterates ASTTraitUsenodes unconditionally. A trait may be registered via reflection (present inexisting_traits) but absent fromClassLikeStorageProvider::$storage. The call togetTraitNode()→classlike_storage_provider->get()throwsInvalidArgumentException.Fix: Add a 4-line
has()guard before accessing trait storage, same pattern as the interface fix in 03037f7.Real-world trigger: Any Laravel class extending
Illuminate\Console\Command(which usesPromptsForMissingInputtrait) with an uninitialized typed property that triggerscollect_initializations→getMethodMutations→ crash.Stack Trace
Test
It failed with:
The stack trace matched the expected crash path through
ClassLikeAnalyzer::getMethodMutations()→ClassLikeStorageProvider::get().Notes
Follows the same guard pattern as the interface fix in 03037f7 (#11760)