1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #2667 - don’t check inherited signature return types for accuracy

This commit is contained in:
Brown 2020-01-21 11:07:44 -05:00
parent 36f5c51f01
commit a2e1dfd64e
2 changed files with 113 additions and 2 deletions

View File

@ -663,6 +663,7 @@ class MethodAnalyzer extends FunctionLikeAnalyzer
if ($guide_method_storage->return_type
&& $implementer_method_storage->return_type
&& !$implementer_method_storage->inherited_return_type
&& ($guide_method_storage->signature_return_type !== $guide_method_storage->return_type
|| $implementer_method_storage->signature_return_type !== $implementer_method_storage->return_type)
&& $implementer_classlike_storage->user_defined

View File

@ -2784,7 +2784,79 @@ class ClassTemplateExtendsTest extends TestCase
*/
public function slice(int $start, int $length): ICollection;
}'
]
],
'concreteDefinesNoSignatureTypes' => [
'<?php
interface IView {}
class ConcreteView implements IView {}
/**
* @template-covariant TView as IView
*/
interface IViewCreator {
/** @return TView */
public function view();
}
/**
* @template-covariant TView as IView
* @implements IViewCreator<TView>
*/
abstract class AbstractViewCreator implements IViewCreator {
public function view() {
return $this->doView();
}
/** @return TView */
abstract protected function doView();
}
/**
* @extends AbstractViewCreator<ConcreteView>
*/
class ConcreteViewerCreator extends AbstractViewCreator {
protected function doView() {
return new ConcreteView;
}
}'
],
'concreteDefinesSignatureTypes' => [
'<?php
interface IView {}
class ConcreteView implements IView {}
/**
* @template-covariant TView as IView
*/
interface IViewCreator {
/** @return TView */
public function view() : IView;
}
/**
* @template-covariant TView as IView
* @implements IViewCreator<TView>
*/
abstract class AbstractViewCreator implements IViewCreator {
public function view() : IView {
return $this->doView();
}
/** @return TView */
abstract protected function doView();
}
/**
* @extends AbstractViewCreator<ConcreteView>
*/
class ConcreteViewerCreator extends AbstractViewCreator {
protected function doView() {
return new ConcreteView;
}
}'
],
];
}
@ -3796,7 +3868,45 @@ class ClassTemplateExtendsTest extends TestCase
new Foo(new DoStuffX());',
'error_message' => 'InvalidArgument'
]
],
'concreteDefinesSignatureTypesDifferent' => [
'<?php
interface IView {}
class ConcreteView implements IView {}
class OtherConcreteView implements IView {}
/**
* @template-covariant TView as IView
*/
interface IViewCreator {
/** @return TView */
public function view() : IView;
}
/**
* @template-covariant TView as IView
* @implements IViewCreator<TView>
*/
abstract class AbstractViewCreator implements IViewCreator {
public function view() : IView {
return $this->doView();
}
/** @return TView */
abstract protected function doView();
}
/**
* @extends AbstractViewCreator<ConcreteView>
*/
class ConcreteViewerCreator extends AbstractViewCreator {
protected function doView() {
return new OtherConcreteView;
}
}',
'error_message' => 'InvalidReturnType'
],
];
}
}