Skip to content

Unreachable statement - code above always terminates. when using a string that correspond to a never returning method #13307

@jtattevin

Description

@jtattevin

Bug report

When a method exists in the codebase and is typed as never (such as dd), PHPStan may misinterpret its usage.

If we pass the method name as a string to another method that expects only a string (not a callable), PHPStan still treats it as if the never method is being invoked.

As a result, it assumes the code terminates at that point, and any statement following this line is flagged with the error: Unreachable statement - code above always terminates.

The following example is the same case but with the method named dd2 instead of dd : https://phpstan.org/r/1f90e98a-4562-41e8-ba38-68d35c69ee91

If was discovered when upgrading from 2.1.17 to 2.1.19 (2.1.18 seem fine)

Code snippet that reproduces the problem

https://phpstan.org/r/1116804a-d113-4c00-91b7-b69dc5552c4a

Expected output

No error

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

Thank a lot for the tool, we can focus more on what we want to do and less about the edge case that may occur.

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