Skip to content

Two unbounded generics in conditional return are assumed to be always the same #11430

@paulbalandan

Description

@paulbalandan

Bug report

When a class method contains two unbounded generics which are both used in the condition part of the conditional return, PHPStan thinks that these two would always be the same. In this example:

final class Choice
{
        /**
	 * @template T
         * @template S
         *
         * @param T $value
         * @param S $none
         *
         * @return (T is S ? None : Some<T>)
         */
        public static function from(mixed $value, mixed $none = null): Option
        {
            if ($value === $none) {
                return new None();
            }

            return new Some($value);
	}
}

it is assumed the function will always return None as T would be always the same as S. However, from the dumps it can be shown the correct types are inferred by PHPStan.

Code snippet that reproduces the problem

https://phpstan.org/r/1fbbf61a-a336-4855-9ba8-e873384a5fb1

Expected output

No error for that part.

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