Skip to content

false positive “Match expression does not handle remaining value: int<...>” for match (count(...)) { ...} #12790

Closed

Description

@claudepache

Bug report

If $a is an array for which count($a) can take a finite number of values, then PHPStan fails to detect that all cases of match (count($a)) { } are handled.

This is a regression introduced between 2.1.9 and 2.1.11

Code snippet that reproduces the problem

https://phpstan.org/r/77f61362-880f-48fa-8cce-1b05da105527

Expected output

No “match.unhandled” error.

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

No response

Activity

  1. changed the title [-]false positive “Match expression does not handle remaining value: int<...>” match (count(...))[/-] [+]false positive “Match expression does not handle remaining value: int<...>” for `match (count(...)) { ...}`[/+] on Mar 24, 2025
  2. added this to the Easy fixes milestone on May 5, 2025
  3. phpstan-bot commented on Mar 16, 2026

    @phpstan-bot
    Contributor

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

    @@ @@
     ==========
     
      8: Dumped type: int<1, 2>
    -10: Match expression does not handle remaining value: int<1, 2>
    +10: Match expression does not handle remaining value: 1
     
     PHP 7.2 – 7.4 (1 error)
     ==========
     
     11: Syntax error, unexpected T_DOUBLE_ARROW on line 11
    Full report

    PHP 8.0 – 8.4 (2 errors)

    Line Error
    8 Dumped type: int<1, 2>
    10 Match expression does not handle remaining value: 1

    PHP 7.2 – 7.4 (1 error)

    Line Error
    11 Syntax error, unexpected T_DOUBLE_ARROW on line 11
  4. phpstan-bot commented on Mar 16, 2026

    @phpstan-bot
    Contributor

    Closed via merging phpstan/phpstan-src#5228

  5. github-actions commented on Apr 17, 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.

  6. locked as resolved and limited conversation to collaborators on Apr 17, 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