Skip to content

fix(translator): let a trailing child variadic absorb parent parameters - #54

Open
AlessioGiacobbe wants to merge 1 commit into
swoole:masterfrom
AlessioGiacobbe:split/override-variadic-absorb
Open

fix(translator): let a trailing child variadic absorb parent parameters#54
AlessioGiacobbe wants to merge 1 commit into
swoole:masterfrom
AlessioGiacobbe:split/override-variadic-absorb

Conversation

@AlessioGiacobbe

Copy link
Copy Markdown
Contributor

A trailing child variadic absorbing parent parameters was rejected: parent f(int $a, int $b), child f(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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant