Repository navigation
fix(weaving): copy the imports of the namespace block declaring the woven class - #758
Merged
Merged
Conversation
…oven class A file may declare the same namespace in several blocks, each with its own imports. WeavingTransformer::processSingleClass() looked the imports up again with `new ReflectionFileNamespace($file, $namespaceName)`, which returns the first block of that name, so the proxy of a class declared in a later block got the imports of the first block: a parameter default like `Level::LEVEL` then referred to the wrong class. The imports are now read from the ReflectionFileNamespace being woven, passed down from transform(). This also drops the second namespace lookup per woven class. Extracted from the declined #757 (#749). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KXjD75egSqDNujmNS5kr5c
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #758 +/- ##
============================================
+ Coverage 97.61% 97.63% +0.01%
+ Complexity 1830 1829 -1
============================================
Files 104 104
Lines 4831 4829 -2
============================================
- Hits 4716 4715 -1
+ Misses 115 114 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
What and why
This bug fix comes from the declined #757 (#749). It has nothing to do with the AST cache limit.
The bug: a file may declare the same namespace in several blocks, each with its own imports:
WeavingTransformer::processSingleClass()looked the imports up again withnew ReflectionFileNamespace($file, $namespaceName), which returns the first block of that name. The proxy ofSecondBlockClasstherefore gotuse Go\Stubs\Collision\Interceptor as Level;, and the copied parameter defaultLevel::LEVELreferred to the wrong class.The fix:
processSingleClass()now receives theReflectionFileNamespacebeing woven fromtransform()and reads the imports from it. As a side effect, this removes the second namespace lookup per woven class, along with itsgetFileName()guard, which nothing else in the method used.Tests
WeavingTransformerTest::testProxyCopiesImportsOfTheNamespaceBlockDeclaringTheClasswith fixture_files/duplicate-ns.php. It asserts that the proxy importsThe as Level, contains noInterceptorimport, keeps theLevel::LEVELdefault, and compiles.src/and passes with the fix.Checklist
type(scope): summary)composer checkpasses🤖 Generated with Claude Code
https://claude.ai/code/session_01KXjD75egSqDNujmNS5kr5c
Generated by Claude Code