Skip to content

Generic return type gets corrupted by throw statement #4422

@vojtech-dobes

Description

@vojtech-dobes

Bug report

I have function with generic callable argument - using generics I describe that the function returns whatever the callback returns.

The problem is when I:

  • pass the callback as anonymous function
  • which actually has native return type hint
  • but throws instead

Code snippet that reproduces the problem

https://phpstan.org/r/d0bf24b0-f404-43f0-b000-1c409ae19aa1#

Expected output

I think the native return type hint shouldn't be overridden by throwing (which I guess resolves it to never), and therefore the snippet above shouldn't report any error. If you think otherwise, could you please explain the philosophy behind that? I've experienced this new behaviour when updating from 67 to 69.

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