Skip to content

A bound new Box(...) coerces a constructor argument that does not fit the binding's template type. #136

Closed

Description

@blacktrs

Summary

A bound new Box(...) coerces a constructor argument that does not fit the binding's template type.

Repro

<?php
/** @template T */
final class Box
{
    public string $kind;
    /** @param T $v */
    public function __construct(mixed $v) { $this->kind = get_debug_type($v); }
    /** @param T $v */
    public function same(mixed $v): string { return get_debug_type($v); }
}
/** @var Box<string> $b */
$b = new Box(5);
echo $b->kind, "\n";
/** @var Box<int> $c */
$c = new Box(2.5);
echo $c->kind, "\n";

Expected (php)

int
float

Actual (manticore 9358b6db, Darwin arm64)

string
int

Tracking

Known-bug repro: tests/aot/repro/wrong/reified_ctor_coerces_misfit_arg.php — bash tests/aot/xfail.sh -k reified_ctor_coerces_misfit_arg reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

Activity

  1. added
    bug
    wrong-answer
    on Oct 8, 2026
  2. added
    needs-design
    area:types
    on Oct 13, 2026
  3. blacktrs commented on Oct 13, 2026

    @blacktrs
    ContributorAuthor

    Scope: decision needed (throw vs route to origin). A reified/bound generic coerces a misfit argument to the binding's type. The direct call path to the specialized class coerces; the existing claimParams/claimCheck route to the origin body exists only for erased thunks and only when the layout matches. For a layout-changing binding (e.g. Bag<float>) the origin body cannot run on the object, so the options are: (a) throw TypeError/ValueError at the boundary (matches the 'narrowing out of range is explicit, never silent' rule), or (b) give up the binding. Proposed: (a), with the check added at direct call sites. Found in batch E; not changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:typesbugneeds-designwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions