Skip to content

Match reporting unhandled enum #6394

@mewejo

Description

@mewejo

Bug report

I have an enum, and I'm using it in a match() and providing options for all of the enum's cases. PHPStan is throwing Match expression does not handle remaining value: EntryType

In my example it's instead throwing Match expression does not handle remaining value: string which is wrong too.

The same result happens with backed and unbacked enums.

Code snippet that reproduces the problem

https://phpstan.org/r/dc525a54-542e-40a9-914f-986088e5c791

<?php declare(strict_types = 1);

enum EntryType: string
{
	case CREDIT = 'credit';
	case DEBIT = 'debit';
}

function getType(int $x): EntryType
{
	return $x > 0 ? EntryType::CREDIT : EntryType::DEBIT;
}

function getAmount(): int
{
	return match(getType(rand(0, 1))) {
		EntryType::DEBIT => 100,
		EntryType::CREDIT => -100
	};
}

Expected output

All cases are matched, I don't expect an error.

Did PHPStan help you today? Did it make you happy in any way?

PHPStan does make me happy. Appreciate all the work you do! Thank you :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions