Skip to content

[Bug] Invalid LessSpecificImplementedReturnType #2569

@azjezz

Description

@azjezz

snippet : https://psalm.dev/r/9ed57c8ff1

code :

<?php

/**
 * @template Tk of array-key
 * @template Tv
 */
interface ICollection {
  /**
   * @psalm-return ICollection<Tk, Tv>
   */
  public function slice(int $start, int $length): ICollection; 
}

/**
 * @template T
 *
 * @extends ICollection<int, T>
 */
interface IVector extends ICollection {
  /**
   * @psalm-return IVector<T>
   */
  public function slice(int $start, int $length): IVector; 
}

expected output :

No Issues!

actual output :

Psalm output (using commit 55aceb2):

ERROR: LessSpecificImplementedReturnType - 21:20 - The inherited return type 'ICollection<int, T:IVector as mixed>' for ICollection::slice is more specific than the implemented return type for IVector::slice 'IVector<T:IVector as mixed>'

hack code :

namespace Psalm\LessSpecificImplmenetedReturnType;

interface ICollection<Tk as arraykey, Tv> {
  public function slice(
    int $start,
    int $length
  ): ICollection<Tk, Tv>;
}

interface IVector<T> extends ICollection<int, T> {
  public function slice(
    int $start,
    int $length
  ): IVector<T>;
}

hack type checker output :

No Errors!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions