Skip to content

foreach over a typed array bound to a #[TypeDef] yields the plain scalar, not the element type #107

Closed

Description

@blacktrs

Summary

foreach over a typed array bound to a #[TypeDef] yields the plain scalar, not the element type.

Repro

<?php
use Manticore\Ds\UInt16Array;

#[TypeDef(repr: 'u16')]
final class Kind
{
    public function __construct(public readonly int $value) {}
    public function isComment(): bool { return $this->value === 7; }
}

/** @var UInt16Array<Kind> $k */
$k = new UInt16Array(2);
$k[0] = new Kind(7);
foreach ($k as $kind) { echo $kind->isComment() ? 'C' : '.'; }
echo "\n";

Expected (php)

C.

Actual (manticore ac9dc28e, Darwin arm64)


[exit code 255]
PHP Fatal error:  Uncaught Error: Call to undefined method object::isComment()

Tracking

Known-bug repro: tests/aot/repro/wrong/typedef_array_foreach_yields_plain_scalar.php — bash tests/aot/xfail.sh -k typedef_array_foreach_yields_plain_scalar 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 6, 2026
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

    bugwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions