Skip to content

Generic type inference failure #9652

@Creeperface01

Description

@Creeperface01

Bug report

If I write the mapping function like this I get error from phpstan that it is unable to infer the type
https://phpstan.org/r/81562057-9a62-46a3-8668-9a2bcc57398d

On the other hand if I make explicit cast to int I get error Casting to int something that's already int. so apparently phpstan is able to infer the type in this case
https://phpstan.org/r/49a2b60f-81e8-42ba-8655-82e0956abb98

Code snippet that reproduces the problem

https://phpstan.org/r/81562057-9a62-46a3-8668-9a2bcc57398d
https://phpstan.org/r/dc37f037-a491-49ae-a8b0-80d99114778b

Expected output

Either phpstan should infer the type or not showing error about useless cast

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