Skip to content

match with heterogeneous mixed arms (object/array/string) dies at runtime coercing the object arm to string #488

Description

@mirchaemanuel

Summary

A match whose arms return heterogeneous mixed values (object / array / string) compiles but dies at runtime — the match-arm type unification appears to coerce the object arm to string.

Verified on

main (7396e65b), macOS ARM64.

Minimal reproduction

<?php
function pick(int $n): mixed {
    return match($n % 3) { 0 => new stdClass(), 1 => [1, 2], default => "s" };
}
$c = 0;
for ($n = 0; $n < 6; $n++) {
    $v = pick($n);
    $c += is_object($v) ? 10 : (is_array($v) ? 7 : 3);
}
echo $c;

Actual

Runtime fatal (Object of class stdClass could not be converted to string), no output.

Expected (PHP)

40

Notes

Found while stress-testing mixed-value shapes for the #484 review. The arms individually work; it is the heterogeneous unification of the match result that mis-coerces.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions