Skip to content

by-ref @param-out should not complain about unused types unless final #12080

@thg2k

Description

@thg2k

Bug report

I believe param-outs should follow the same logic as the return type, and not complain for unused types to allow for covariance in derived classes, unless the method or the class is final of course, or it's a function.

class C {
  /**
   * @param mixed $x
   * @param-out string|int $x
   */
  public function foo(&$x): void {
    // Method C::foo() never assigns int to &$x so it can be removed from the @param-out type.
    $x = "foo";
  }
}

class D extends C {
  public function foo(&$x): void {
    // Method D::foo() never assigns string to &$x so it can be removed from the @param-out type.
    $x = 42;
  }
}

Code snippet that reproduces the problem

https://phpstan.org/r/17b75b5d-b375-495e-8814-75ee40785759

Expected output

No error

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

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions