Skip to content

[Core] Drop file positions on reprinted nodes copied from another file - #8928

Merged
TomasVotruba merged 2 commits into
mainfrom
fix-inherited-constructor-positions
Nov 9, 2026
Merged

TomasVotruba merged 2 commits into
mainfrom
fix-inherited-constructor-positions

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9963

ClassDependencyManipulator::resolveConstruct() clones the parent __construct() and passes it to NodeFactory::createReprintedNode(). That cleared ORIGINAL_NODE, but kept startFilePos/endFilePos/token positions from the parent's file.

On scope refresh, BetterReflection scans for a trailing param comment from endFilePos + 1 in the child's source. When the parent constructor sits deeper in its file than the child file is long, this crashes with Failed to scan trailing parameter comment. When the offset fits, it reads unrelated bytes of the child.

Now createReprintedNode() also drops file and token positions. BetterReflection skips the scan when endFilePos is missing.

Test: a test-only rule adds a constructor dependency to a child whose parent constructor is far into another file. Fails on main with the crash, passes with the fix.

The shared Cache service keeps the directory it was first built with, while the
entry count read the current cache_dir parameter. Depending on test order, the two
pointed at different directories.
@TomasVotruba
TomasVotruba merged commit 6029e8d into main Nov 9, 2026
51 checks passed
@TomasVotruba
TomasVotruba deleted the fix-inherited-constructor-positions branch November 9, 2026 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

"Failed to scan trailing parameter comment" when constructor injection copies an inherited constructor from another file

1 participant