🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

Generic type information lost after comparison operation #10083

Description

@JoyceBabu

Bug report

When a generic type is compared with a value, the type information is lost.

<?php

enum Foo {
	case Abc;
	case Bcd;
}

/**
 * @template TFoo of Foo::*
 * @param  TFoo $foo
 */
function checkFoo($foo): void {
	
}

/**
 * @template TFoo of Foo::*
 * @param  TFoo $foo
 */
function getFoo1($foo): void {
	$filter = Foo::Abc === $foo ? 'Abc' : 'Bcd';

	checkFoo($foo); // Error: Parameter #1 $foo of function checkFoo expects Foo::Abc|Foo::Bcd, TFoo given.
}

/**
 * @template TFoo of Foo::*
 * @param  TFoo $foo
 */
function getFoo2($foo): void {
	checkFoo($foo);
}

Code snippet that reproduces the problem

https://phpstan.org/r/7118dd81-84cc-40cb-826f-8ae2c8caa2f3

Expected output

PHPStan should not forget the type of the generic variable.

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