Skip to content

False positive match.unhandled when using match on enum|null with generic #13048

@vjik

Description

@vjik

Bug report

enum IndexBy {
	case A;
	case B;
}

/**
 * @template T of IndexBy|null
 * @param T $indexBy
 * @return (T is null ? null : string)
 */
function run(?IndexBy $indexBy = null): ?string
{
	return match ($indexBy) {
		IndexBy::A => 'by A',
		IndexBy::B => 'by B',
		null => null,
	};
}

Error: Match expression does not handle remaining value: T of mixed

Seems, this bug is similar to #12998

Code snippet that reproduces the problem

https://phpstan.org/r/3448c780-b995-4e14-9ec2-9c37d01b7d6f

Expected output

No errors

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

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions