Skip to content

incorrect type narrowing with combination of two dependent variables #14191

Closed

Description

@claudepache

Bug report

Probably since 2.1.40. See code snippet.

Code snippet that reproduces the problem

https://phpstan.org/r/d7b0e719-b39e-44d0-90a0-6f2079c25eae

Expected output

  • Line 33: same output as line 31 (the assertion on line 32 does not imply anything on $display_list)
  • Line 34: Dumped type: true

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

No response

Activity

  1. claudepache commented on Feb 23, 2026

    @claudepache
    Author

    Simplified testcase:

    Code snippet that reproduces the problem

    https://phpstan.org/r/b28b8c9b-f4c8-40b2-ada3-c883650199a2

    Expected output

    • Line 31: Dumped type: bool
  2. claudepache commented on Feb 24, 2026

    @claudepache
    Author

    Strangely, if I declare $list_of_ids as array<int> instead of list<int>, the bug disappears:

    https://phpstan.org/r/bccbbab6-70a2-4355-9d2e-d37400cb0c1d

  3. added this to the Dependent types milestone on Feb 24, 2026
  4. phpstan-bot commented on Feb 24, 2026

    @phpstan-bot
    Contributor

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

    @@ @@
     26: Dumped type: false
     31: Dumped type: bool
    -33: Dumped type: true
    -34: Dumped type: *NEVER*
    +33: Dumped type: bool
    +34: Dumped type: true
    Full report
    Line Error
    26 Dumped type: false
    31 Dumped type: bool
    33 Dumped type: bool
    34 Dumped type: true
  5. phpstan-bot commented on Feb 24, 2026

    @phpstan-bot
    Contributor

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

    @@ @@
    -31: Dumped type: true
    +31: Dumped type: bool
    Full report
    Line Error
    31 Dumped type: bool
  6. ondrejmirtes commented on Feb 24, 2026

    @ondrejmirtes
    Member
  7. claudepache commented on Feb 24, 2026

    @claudepache
    Author

    That was fast! Thank you.

  8. github-actions commented on Mar 28, 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 Mar 28, 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