Skip to content

Anonymous polymorphic functions are not composable #12038

@klimick

Description

@klimick

Bug report

You asked to open various small issues here:

I'm closing this issue because the samples shown are incoherent and show different issues. Please open separate GitHub issues for each scenario, thanks.

First was: #11942

The current issue concerns composition.
For example flip(zip(...)).

If you are not familiar with the flip and zip functions, here are a couple of examples:

  1. Example with flip:
    https://phpstan.org/r/218774fb-0475-4915-a7a6-e875b98fa1d8
  2. Example with zip:
    https://phpstan.org/r/b9924428-b2ba-4d06-a460-b3d18314879d

PHPStan handles them individually.
But when these functions are used together, PHPStan fails to infer the correct type.
Furthermore, due to incorrect type inference, PHPStan erronusly prevents calling $flipZip

Code snippet that reproduces the problem

https://phpstan.org/r/6853f106-dd9e-481b-98ee-9fde699b2889 (flipZip)
https://phpstan.org/r/1da40e71-8b5d-4b4c-ae1d-105c403dd297 (More test cases with compose)

Expected output

Actual inferred type:
Dumped type: callable(list<B>, list<A>): list<array{A, B}>

Expected inferred type:
Dumped type: callable<A, B>(list<B>, list<A>): list<array{A, B}>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions