Skip to content

Conditional type in @param - Call to method Xxx::xxx() with true will always evaluate to true. #10337

Closed

Description

@mvorisek

Bug report

Conditional type in @param can have always true condition, but such tautology in it is completely expected and phpstan error must not emit any error for it.

Code snippet that reproduces the problem

https://phpstan.org/r/676a25bf-8118-4353-937f-2660308e8b47

Expected output

no phpstan error

Activity

  1. added this to the Easy fixes milestone on Dec 31, 2023
  2. phpstan-bot commented on Sep 19, 2024

    @phpstan-bot
    Contributor

    @mvorisek After the latest push in 2.0.x, PHPStan now reports different result with your code snippet:

    @@ @@
     24: Result of method App::callExit() (void) is used.
     28: Call to method App::callExit() with true will always evaluate to true.
     28: Result of method App::callExit() (void) is used.
    -37: Call to method class@anonymous/tmp.php:30::callExit() with true will always evaluate to true.
    -37: Result of method class@anonymous/tmp.php:30::callExit() (void) is used.
    +37: Call to method App@anonymous/tmp.php:30::callExit() with true will always evaluate to true.
    +37: Result of method App@anonymous/tmp.php:30::callExit() (void) is used.
    Full report
    Line Error
    20 Call to method App::callExit() with true will always evaluate to true.
    24 Call to method App::callExit() with true will always evaluate to true.
    24 Result of method App::callExit() (void) is used.
    28 Call to method App::callExit() with true will always evaluate to true.
    28 Result of method App::callExit() (void) is used.
    37 Call to method App@anonymous/tmp.php:30::callExit() with true will always evaluate to true.
    37 Result of method App@anonymous/tmp.php:30::callExit() (void) is used.
  3. phpstan-bot commented on Jul 21, 2025

    @phpstan-bot
    Contributor

    @mvorisek After the latest push in 2.1.x, PHPStan now reports different result with your code snippet:

    @@ @@
     20: Call to method App::callExit() with true will always evaluate to true.
    -24: Call to method App::callExit() with true will always evaluate to true.
    -24: Result of method App::callExit() (void) is used.
    -28: Call to method App::callExit() with true will always evaluate to true.
    -28: Result of method App::callExit() (void) is used.
    -37: Call to method App@anonymous/tmp.php:30::callExit() with true will always evaluate to true.
    -37: Result of method App@anonymous/tmp.php:30::callExit() (void) is used.
    +24: Unreachable statement - code above always terminates.
    Full report
    Line Error
    20 Call to method App::callExit() with true will always evaluate to true.
    24 Unreachable statement - code above always terminates.
  4. mvorisek commented on Jul 21, 2025

    @mvorisek
    ContributorAuthor

    @staabm phpstan/phpstan-src#4090 has broken this repro. It seems conditional never is wrongly assumed as always instead of maybe.

  5. staabm commented on Jul 21, 2025

    @staabm
    Contributor

    I am not sure what you mean with broken...?

    It looks like after the first call which we know will never return everything is unreachable (which I think is expected).

    The initial error/bug you reported on line 20 is still there.

    IMO its now more correct than before (with the same bug in line20)

  6. mvorisek commented on Jul 21, 2025

    @mvorisek
    ContributorAuthor

    Thank you. I see you are correct, I was reading the "Unreachable statement - code above always terminates." error to be for a line 20, but it is for line 24 (thanks to line 23). This is expected. I will update my repro.

  7. phpstan-bot commented on Mar 3, 2026

    @phpstan-bot
    Contributor

    Closed via merging phpstan/phpstan-src#5121

  8. github-actions commented on Apr 4, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  9. locked as resolved and limited conversation to collaborators on Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions