Skip to content

False positive: Array shapes in generics with nullable values on levels below 8 #9377

Closed

Description

@canvural

Bug report

When a class has array shape in one of it's generic arguments, and the type is compared against the same exact thing PHPStan produces an error on levels below 8 with bleeding edge enabled. But error does not happen on level 8.

Code snippet that reproduces the problem

https://phpstan.org/r/ce1665bb-593e-41ca-b0be-960acc6f1ae1

Expected output

Covariance really confuses me. So, either the error should also happen on level 8 or should not happen on levels below 8 too.

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

Always ❤️

Activity

  1. ondrejmirtes commented on May 30, 2023

    @ondrejmirtes
    Member

    Yeah, level 8 is correct here (there should be no errors) because it no longer touches and corrupts nullable types like int|null.

  2. added this to the Generics milestone on May 30, 2023
  3. phpstan-bot commented on Mar 29, 2024

    @phpstan-bot
    Contributor

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

    @@ @@
    +12: Function foo() returns void but does not have any side effects.
     23: Parameter #1 $foo of function foo expects HelloWorld<array{id: int|null}>, HelloWorld<array{id: int|null}> given.
    Full report
    Line Error
    12 Function foo() returns void but does not have any side effects.
    23 `Parameter #1 $foo of function foo expects HelloWorld<array{id: int
  4. deleted a comment from phpstan-bot on Apr 17, 2024
  5. VincentLanglet commented on Aug 2, 2025

    @VincentLanglet
    Contributor

    This is the same issue than #9096 (comment)

  6. phpstan-bot commented on Sep 7, 2026

    @phpstan-bot
    Contributor

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

    @@ @@
    +18: Function bar() should return HelloWorld<array{id: int|null}> but returns HelloWorld<array{id: int|null}>.
     23: Parameter #1 $foo of function foo expects HelloWorld<array{id: int|null}>, HelloWorld<array{id: int|null}> given.
    Full report
    Line Error
    18 `Function bar() should return HelloWorld<array{id: int
    23 `Parameter #1 $foo of function foo expects HelloWorld<array{id: int
  7. phpstan-bot commented on Sep 10, 2026

    @phpstan-bot
    Contributor

    Closed via merging phpstan/phpstan-src#6392

  8. github-actions commented on Oct 12, 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 Oct 12, 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