Skip to content

Function should return int|(T of int|null) but returns T (which is int|null). #12989

@rx80

Description

@rx80

Bug report

Maybe i am missing some detail, but i think this code shouldn't report a type mismatch:

/**
 * @template T of int|null
 * @phpstan-param T $b
 * @phpstan-return int|T
 */
function a(?int $b): ?int
{
    if ($b === null) {
        return $b; // phpstan reports: Function a() should return int|(T of int|null) but returns T.
    }

    return $b;
}

Code snippet that reproduces the problem

https://phpstan.org/r/fbce81ec-7a7c-46e0-afb0-44d01d9e69b5

Expected output

Expected: no type error

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