Psalm: [LessSpecificImplementedReturnType] phpDoc not inherited when adding a more specified native type

Created on 1 May 2019  路  2Comments  路  Source: vimeo/psalm

Not sure if this is intentional

<?php

class Foo
{
  /**
   * @return int[]
   */
  public function doFoo()
  {
    return [1, 2, 3];
  }
}

class Bar extends Foo
{
  public function doFoo(): array
  {
    return parent::doFoo();
  }
}

ERROR: LessSpecificImplementedReturnType - 16:28 - The return type 'array' for Foo::doFoo is more specific than the implemented return type for Bar::dofoo 'array'

https://psalm.dev/r/483659eb7f

Bar::doFoo added a more specific native return type but IMO the phpDoc type should still be inherited. Otherwise the phpDoc types just have to be copied manually.

bug

Most helpful comment

Oh thanks for this - this was reported by @jwage last week, but from a more convoluted scenario. This is a great test case.

All 2 comments

Oh thanks for this - this was reported by @jwage last week, but from a more convoluted scenario. This is a great test case.

Cool, thank you 馃檪

Was this page helpful?
0 / 5 - 0 ratings

Related issues

greg0ire picture greg0ire  路  3Comments

vudaltsov picture vudaltsov  路  3Comments

Pierstoval picture Pierstoval  路  3Comments

caugner picture caugner  路  3Comments

orklah picture orklah  路  3Comments