Skip to content

False positive method.notFound when using @phpstan-assert-if-true static<A> $this #12820

Closed
phpstan/phpstan-src
#6836

Description

@gharlan

Bug report

Coming from #12752.

Code snippet that reproduces the problem

https://phpstan.org/r/9eb23e31-92a3-41e0-9f85-731ee7f3f5b2

Expected output

No errors.

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

No response

Activity

  1. added this to the Generics milestone on May 5, 2025
  2. phpstan-bot commented on Oct 24, 2026

    @phpstan-bot
    Contributor

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

    @@ @@
    -PHP 8.0 – 8.4 (1 error)
    +PHP 8.0 – 8.4
     ==========
     
    -29: Call to an undefined method (T of A = A|B)|T of B = A|B::a().
    +No errors
     
    -PHP 7.2 – 7.4 (3 errors)
    +PHP 7.2 – 7.4 (2 errors)
     ==========
     
      4: Constructor of class A has a return type.
    -17: Method FooInterface::get() uses native union types but they're supported only on PHP 8.0 and later.
    -29: Call to an undefined method (T of A = A|B)|T of B = A|B::a().
    +17: Method FooInterface::get() uses native union types but they're supported only on PHP 8.0 and later.
    Full report

    PHP 8.0 – 8.4

    No errors

    PHP 7.2 – 7.4 (2 errors)

    Line Error
    4 Constructor of class A has a return type.
    17 Method FooInterface::get() uses native union types but they're supported only on PHP 8.0 and later.
  3. staabm commented on Oct 25, 2026

    @staabm
    Contributor

    Needs a regression test

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