Repository navigation
Fix the crash on a global namespace block after a named one - #70
Merged
Merged
Conversation
"namespace { ... }" has no name, so reading it crashed with "Call to a
member function toString() on null". It now resets the namespace and
the use statements like any other namespace, so hook docblocks in it
don't resolve names through the previous block's imports.
Fixes #58
Co-authored-by: Alain Schlesser <83631+schlessera@users.noreply.github.com>
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.
Context
A file with a braced global namespace block after a named one crashes the plugin:
namespace { ... }has no name, andHookNodeVisitor::enterNode()calls$node->name->toString()on everyNamespace_node. Fixes #58.Solution
A nameless block now sets the current namespace to the global one (
'') and clears theusestatements, like any other namespace block.#59 avoids the crash by skipping nameless blocks, but then the global block keeps the previous block's namespace and imports. Hook docblocks are resolved with them, so in the example above
@param Item $itembecomesShop\Catalog\Product, andapply_filters( 'hook', new Item() )reportsInvalidArgument. The new test case covers both: it crashes without the fix and reports thatInvalidArgumentwith #59's check. This PR supersedes #59; thanks @schlessera for the report and the first fix (co-author of the commit).