Skip to content

@param with union type of T|Closure(): T returns false positive #7049

Closed

Description

@taka-oyama

Bug report

Code snippet that reproduces the problem

https://phpstan.org/r/53bef65c-5e31-464b-8d62-3a4cdd778b2a

Expected output

No errors.

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

This helped me find so many bugs! Thank you!

Activity

  1. changed the title [-]@param with union type of template type and a Closure that returns template type returns false positive[/-] [+]@param with union type of T|Closure(): T returns false positive[/+] on Apr 17, 2022
  2. added this to the Generics milestone on Apr 21, 2022
  3. phpstan-bot commented on Mar 4, 2025

    @phpstan-bot
    Contributor

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

    @@ @@
    -PHP 8.0 – 8.1 (1 error)
    +PHP 8.0 – 8.1 (2 errors)
     ==========
     
    +17: Call to method Collection::groupBy() on a separate line has no effect.
     17: Unable to resolve the template type TGroupKey in call to method Collection::groupBy()
     
    -PHP 7.1 – 7.4 (2 errors)
    +PHP 7.1 – 7.4 (3 errors)
     ==========
     
     10: Method Collection::groupBy() uses native union types but they're supported only on PHP 8.0 and later.
    +17: Call to method Collection::groupBy() on a separate line has no effect.
     17: Unable to resolve the template type TGroupKey in call to method Collection::groupBy()
    Full report

    PHP 8.0 – 8.1 (2 errors)

    Line Error
    17 Call to method Collection::groupBy() on a separate line has no effect.
    17 Unable to resolve the template type TGroupKey in call to method Collection::groupBy()

    PHP 7.1 – 7.4 (3 errors)

    Line Error
    10 Method Collection::groupBy() uses native union types but they're supported only on PHP 8.0 and later.
    17 Call to method Collection::groupBy() on a separate line has no effect.
    17 Unable to resolve the template type TGroupKey in call to method Collection::groupBy()
  4. phpstan-bot commented on Sep 9, 2026

    @phpstan-bot
    Contributor

    Closed via merging phpstan/phpstan-src#6376

  5. github-actions commented on Oct 11, 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 Oct 11, 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