Skip to content

Closure return type inference #3091

@fmasa

Description

@fmasa

Feature request

Since PHP 7.4 we have support for short closures fn (int $x) => foo($x), but AFAIK PHPStan cannot infer return type of even these single-statement closures and mixed is considered to be return type. So in order to get type checking, return type must be explicitly specified, which makes the new concise syntax unnecessarily long again.
I think that PHPStan should infer the return type of short (and normal) closures, when none is explicitly set.

I can probably help with implementation, I just need a few pointers and confirmation that this feature makes sense to you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions