Skip to content

Unexpected <array<array<T>>> reported by PHPStan when using template types #11032

@SimonFrings

Description

@SimonFrings

Bug report

I'm currently running into a weird behavior with arrays when trying to improve template type support in our ReactPHP Async component. Here's a quick rundown:

We added PHPStan template types (reactphp/promise#247) as part of our ReactPHP Promise v3 release last year. Afterwards I released new versions of our Async component (Async v4.2.0 & Async v3.2.0), but unfortunately broke our test suite because of some unresolved PHPStan errors (my bad). In order to fix this, I created reactphp/async#86.

Adding the missing Promise v3 template types was an easy fix in most cases, but for some reason didn't quite work for our parallel() and series() functions. When I tried to define the Deferred (see PHPStan playground example below) I would expect for that function to return a PromiseInterface<array<T>> but for some reason PHPStan says it returns a PromiseInterface<array<array<T>>>. I'm don't know why this is happening but I'd expect this to work.

I know when running this with bleeding edge it works and I tried to look for similar tickets but didn't found one to add my case to. Hope you can shine some light on this, interested if we're using something wrong or if PHPStan is handling this incorrectly.

Code snippet that reproduces the problem

https://phpstan.org/r/092ba6ff-3764-4f09-8dc6-c0e109913c60

Expected output

Expecting to see a PromiseInterface<array<T>> as the return type but PHPStan sees a PromiseInterface<array<array<T>>>

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