fix(translator): let a trailing child variadic absorb parent parameters - #54
Open
AlessioGiacobbe wants to merge 1 commit into
Open
fix(translator): let a trailing child variadic absorb parent parameters#54AlessioGiacobbe wants to merge 1 commit into
AlessioGiacobbe wants to merge 1 commit into
Conversation
Zend's zend_do_perform_implementation_check does not compare variadic-ness
per position. Its rules are:
- a variadic parent requires a variadic child (unbounded contract);
- a trailing child variadic stands in for every remaining parent
position (decorator pattern), with the variadic's type checked for
contravariance against each covered parent parameter and by-ref-ness
matched per position;
- when the parent is variadic, extra child parameters are validated
against the parent's variadic slot.
validateMethodOverrideSignature required an exact per-position variadic
match, rejecting valid programs such as parent f(int $a, int $b)
overridden by f(int ...$args). Rework the position loop per the Zend
rules; the required-argument-count and extra-optional-parameter checks
are unchanged.
The pre-existing testVariadicMismatch expectation (untyped f($x)
overridden by f(...$x) must fail) contradicts Zend 8.4, which accepts
it; the test now asserts the program compiles.
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.
A trailing child variadic absorbing parent parameters was rejected: parent
f(int $a, int $b), childf(int ...$args)failed "must be compatible", breaking the common decorator/proxy pattern (Zend accepts it). The per-position loop required exact variadic equality at each index.The loop now follows Zend's rules: a variadic parent requires a variadic child; a trailing child variadic covers every remaining parent position (contravariant type, matching by-ref-ness per position); extra child parameters must stay optional. The pre-existing testVariadicMismatch encoded the rejects-valid behavior (verified against Zend) and was updated to assert compilation.
Verified against Zend 8.4.13, 11-case probe matrix.
Part of the split of #39.