🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

asserting Foo<T>|T is Foo should result in Foo<T>|Foo not Foo<T> #13190

Description

@azjezz

Bug report

In here, i'm expecting return $to_box; in the inbox function to fail, as $to_box is known to be Box or Box<unknown> at this point, not Box<T>. as T has no constraints, and could itself be a Box.

This can cause actual problems down the line as shown with the following code, where phpstan incorrectly infers $box to be Box<Box<int>> where in reality, it is Box<int>.

Triggering an error at inbox will make the user rethink their design choice here, and won't allow for such bugs.

ref: vimeo/psalm#11492

Code snippet that reproduces the problem

https://phpstan.org/r/539c3023-65bf-46fa-a9d0-d09ce9cf1b17

Expected output

return $to_box; should trigger an invalid return statement error, as $to_box is Box<T>|Box, not Box<T>.

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions