Jean-FrancoisHIVERT but in your case, it is:
public function test(): SimpleClass {
return $this->_test(); // <-- ParentClass
}
which is equivalent to:
// ...
class F extends D { public function f1(): C { return new B(); } }
// ...
resulting in
PHP Fatal error: Uncaught TypeError: F::f1(): Return value must be of type C, B returned
The error is really correct - try returning new ParentClass from _test(),
protected function _test(): ParentClass
{
return new ParentClass(); // make it non-abstract
}
Fatal error: Uncaught TypeError: Devsense\Common\ReturnType\MyClass::test(): Return value must be of type Devsense\Common\ReturnType\SimpleClass, Devsense\Common\ReturnType\ParentClass returned
You can "avoid" the runtime error by returning A instead of ParentClass, but then the type hint is misleading.