Skip to content

False positive when using match on class-string from generics #12998

@BenMorel

Description

@BenMorel

Bug report

This code:

class A {}
class B {}

/**
 * @template T of A|B
 *
 * @param class-string<T> $class
 */
function foo(string $class): string
{
	return match ($class) {
		A::class => 'a',
		B::class => 'b',
	};
}

Wrongly (I guess) reports:

Match expression does not handle remaining value: class-string<T of A|B>

Code snippet that reproduces the problem

https://phpstan.org/r/fa06cc1b-6489-4f4b-b03f-86b75e6de217

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