Skip to content

fix: accept object-subtype default for object-typed parameters#462

Merged
nahime0 merged 4 commits into
illegalstudio:mainfrom
chadmandoo:upstream-pr/subtype-default-param
Jul 10, 2026
Merged

fix: accept object-subtype default for object-typed parameters#462
nahime0 merged 4 commits into
illegalstudio:mainfrom
chadmandoo:upstream-pr/subtype-default-param

Conversation

@chadmandoo

Copy link
Copy Markdown
Contributor

What

An object-typed parameter (or constructor-promoted property) with a concrete-subtype default is wrongly rejected:

interface I {}
final class N implements I {}
final class C { public function __construct(public I $x = new N()) {} }
// error: Method parameter $x expects Object("I"), got Object("N")

A plain function f(I $x) called with f(new N()) works — only the default value fails.

Why

validate_declared_default_type runs in the purely-syntactic schema pass, where the class/interface table isn't populated yet, so type_accepts's class_implements_interface spuriously returns false. (The code already has the same leniency for enum-case defaults, for the same reason.)

Fix

Accept an object default for an object-typed parameter in that pass; a genuine mismatch still surfaces at the call site. Byte-parity regression test (the default instantiates + dispatches). Builds standalone on main.

chadmandoo and others added 4 commits July 5, 2026 13:58
…type check)

An interface-typed constructor-promoted property (or param) with a concrete
default — `public ComponentResolverInterface $r = new NullComponentResolver()` —
was rejected: "Method parameter $r expects Object(I), got Object(N)". The default
is validated in the purely-syntactic schema pass, where the class/interface table
isn't populated yet, so type_accepts's class_implements_interface spuriously
returns false. Accept an object default for an object-typed param there (mirroring
the existing enum-case leniency); a genuine mismatch still surfaces at the call
site. Byte-parity regression test. AIC epic illegalstudio#483 / EC-8 (illegalstudio#491), the object-param
sub-part (~14 gaps: ward-forms AlteredForm/Field/... interface-typed promoted props).

(cherry picked from commit db17c17)
@nahime0 nahime0 merged commit 6cb6246 into illegalstudio:main Jul 10, 2026
58 checks passed
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.

2 participants