Skip to content

feat(errors): register UnhandledMatchError as a builtin Error subclass#521

Open
chadmandoo wants to merge 1 commit into
illegalstudio:mainfrom
chadmandoo:upstream-pr/unhandled-match-error
Open

feat(errors): register UnhandledMatchError as a builtin Error subclass#521
chadmandoo wants to merge 1 commit into
illegalstudio:mainfrom
chadmandoo:upstream-pr/unhandled-match-error

Conversation

@chadmandoo

Copy link
Copy Markdown
Contributor

What

UnhandledMatchError — PHP 8's error thrown when a match expression has no matching arm and no default — was not a registered builtin, so a program that references it (including the common default => throw new UnhandledMatchError(...) idiom) failed to type-check.

function classify(int $n): string {
    return match (true) {
        $n < 0   => "neg",
        $n === 0 => "zero",
        default  => throw new UnhandledMatchError("no arm for " . $n),
    };
}
try { classify(5); } catch (\UnhandledMatchError $e) { echo $e->getMessage(); }

How

Register UnhandledMatchError as a builtin class extending Error (the class-name list + the class_map insert in declarations.rs) and include it in the Error-family signature fixup (exception.rs), mirroring TypeError / ValueError / ArithmeticError.

Test

test_unhandled_match_error_throw_and_catch — newable, throwable from a match default arm, catchable by FQN, getMessage() round-trip. Byte-parity vs PHP 8.5.

🤖 Generated with Claude Code

`UnhandledMatchError` (PHP 8's error for a `match` with no matching arm and no
default) is now a registered builtin class extending `Error`: newable with a
message, throwable from a `match` default arm, catchable by name, and its
getMessage() round-trips.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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