Skip to content

Calls to parent::someMethod should remember type params #2621

@muglug

Description

@muglug
/**
 * @template T
 */
class Stringer {
  /**
   * @param T $t
   */
  public static function takesParam($t) : string {
    return "hello";
  }
}

class AParent {}
class A extends AParent {}

/**
 * @template-extends Stringer<A>
 */
class AStringer extends Stringer {
  public static function foo() : string {
    return parent::takesParam("should not be allowed");
  }
}

Expected output

Argument 1 of Stringer::takesParam expects A, string provided

Actual output

No issue - https://phpstan.org/r/c58ef371-1108-4e75-ae3b-b4f9a077ec69

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions