Skip to content

match() does not work on class const fetch #7746

@staabm

Description

@staabm

Bug report

with phpstan/phpstan-src#1590 we added support to use class-strings in match().

there is still one missing piece, in which it does not work when directly putting a class-const-fetch expressions into the match:

works:

	$t = new Test(new A());
	$class = $t->value::class;
	echo match ($class) {
		A::class => 'A',
		B::class => 'B'
	};

doesn't work:

	$t = new Test(new A());
	echo match ($t->value::class) {
		A::class => 'A',
		B::class => 'B'
	};

I think the problem is that GenericClassStringType->tryRemove() is not even called in case we have a expression in the match. it is called as expected in the case we have a variable involved.

Code snippet that reproduces the problem

https://phpstan.org/r/12a4e14f-a742-4f8c-a873-c309b4386189
https://phpstan.org/r/be1b13ce-b8d9-445e-b6ed-dc9e87f2879b shows the problem is more general

Expected output

no error

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