fix(translator): allow overrides to add a by-ref return - #53
Open
AlessioGiacobbe wants to merge 2 commits into
Open
fix(translator): allow overrides to add a by-ref return#53AlessioGiacobbe wants to merge 2 commits into
AlessioGiacobbe wants to merge 2 commits into
Conversation
A git worktree shares vendor/ with the primary checkout via a symlink, and Composer's generated autoloader resolves the TypePhp\ prefix relative to the realpath of vendor/. The suite then silently loads and tests the OTHER checkout's src/ tree. Prepend an autoloader anchored to this checkout so the tests always exercise the sources they ship with; in a standalone checkout this is a no-op.
Zend's inheritance check treats return-by-reference as covariant
(zend_do_perform_implementation_check): an error is raised only when the
parent returns by reference and the child does not. The child adding `&`
is a strictly stronger guarantee and is accepted:
class A { public function f(): array {} }
class B extends A { public function &f(): array {} } // OK in Zend
validateMethodOverrideSignature compared returnsByRef with exact equality,
rejecting this valid program. Make the check one-directional; dropping a
parent's by-ref return remains fatal.
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.
Adding a by-ref return in an override was rejected:
class B extends A { public function &f(): array {...} }over a plainf(): arrayfailed "must be compatible", while Zend only forbids dropping a by-ref promised by the parent (that direction stays rejected).The exact-equality check becomes one-directional. Also includes a small test-infra commit anchoring phpunit's TypePhp autoloading to the current checkout (protects suites run from worktrees with a shared vendor/; a no-op in a standalone checkout).
Verified against Zend 8.4.13; tests both directions.
Part of the split of #39.