diff --git a/docs/running_psalm/issues/MethodSignatureMustProvideReturnType.md b/docs/running_psalm/issues/MethodSignatureMustProvideReturnType.md index 80aa53c8ac2..0c85db90d36 100644 --- a/docs/running_psalm/issues/MethodSignatureMustProvideReturnType.md +++ b/docs/running_psalm/issues/MethodSignatureMustProvideReturnType.md @@ -8,7 +8,6 @@ This issue is emitted when a method overriding a native method is defined withou ```php 'A']; diff --git a/psalm-baseline.xml b/psalm-baseline.xml index dcd0433d3dd..3b9bb725ee3 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + $comment_block->tags['variablesfrom'][0] @@ -21,6 +21,9 @@ $matches[0] $symbol_parts[1] + + $analysis_php_version_id + @@ -659,6 +662,11 @@ array_keys($template_type_map[$template_param_name])[0] + + + MethodSignatureMustProvideReturnType + + VirtualClass diff --git a/src/Psalm/Internal/Analyzer/MethodComparator.php b/src/Psalm/Internal/Analyzer/MethodComparator.php index dd0b6ee6497..16ff2d9d98b 100644 --- a/src/Psalm/Internal/Analyzer/MethodComparator.php +++ b/src/Psalm/Internal/Analyzer/MethodComparator.php @@ -21,14 +21,12 @@ use Psalm\Issue\ImplementedReturnTypeMismatch; use Psalm\Issue\LessSpecificImplementedReturnType; use Psalm\Issue\MethodSignatureMismatch; -use Psalm\Issue\MethodSignatureMustProvideReturnType; use Psalm\Issue\MissingImmutableAnnotation; use Psalm\Issue\MoreSpecificImplementedParamType; use Psalm\Issue\OverriddenMethodAccess; use Psalm\Issue\ParamNameMismatch; use Psalm\Issue\TraitMethodSignatureMismatch; use Psalm\IssueBuffer; -use Psalm\Storage\AttributeStorage; use Psalm\Storage\ClassLikeStorage; use Psalm\Storage\FunctionLikeParameter; use Psalm\Storage\MethodStorage; @@ -37,7 +35,6 @@ use Psalm\Type\Atomic\TTemplateParam; use Psalm\Type\Union; -use function array_filter; use function in_array; use function strpos; use function strtolower; @@ -116,29 +113,6 @@ public static function compare( ); } - if (!$guide_classlike_storage->user_defined - && $implementer_classlike_storage->user_defined - && $codebase->analysis_php_version_id >= 80100 - && ($guide_method_storage->return_type - || $guide_method_storage->signature_return_type - ) - && !$implementer_method_storage->signature_return_type - && !array_filter( - $implementer_method_storage->attributes, - function (AttributeStorage $s) { - return $s->fq_class_name === 'ReturnTypeWillChange'; - } - ) - ) { - IssueBuffer::maybeAdd( - new MethodSignatureMustProvideReturnType( - 'Method ' . $cased_implementer_method_id . ' must have a return type signature!', - $implementer_method_storage->location ?: $code_location - ), - $suppressed_issues + $implementer_classlike_storage->suppressed_issues - ); - } - if ($guide_method_storage->return_type && $implementer_method_storage->return_type && !$implementer_method_storage->inherited_return_type @@ -888,14 +862,7 @@ private static function compareMethodSignatureReturnTypes( $implementer_signature_return_type, $guide_signature_return_type ) - : (!$implementer_signature_return_type - && $guide_signature_return_type->isMixed() - ? false - : UnionTypeComparator::isContainedByInPhp( - $implementer_signature_return_type, - $guide_signature_return_type - ) - ); + : UnionTypeComparator::isContainedByInPhp($implementer_signature_return_type, $guide_signature_return_type); if (!$is_contained_by) { if ($codebase->php_major_version >= 8 diff --git a/tests/DocumentationTest.php b/tests/DocumentationTest.php index f721041cab5..31c392d1aff 100644 --- a/tests/DocumentationTest.php +++ b/tests/DocumentationTest.php @@ -218,10 +218,6 @@ public function testInvalidCode($code, $error_message, $error_levels = [], $chec $this->markTestSkipped(); } - if (strpos($error_message, 'MethodSignatureMustProvideReturnType') !== false) { - $php_version = '8.1'; - } - $this->project_analyzer->setPhpVersion($php_version, 'tests'); if ($check_references) { @@ -293,6 +289,10 @@ public function providerInvalidCodeParse(): array case 'TraitMethodSignatureMismatch': continue 2; + /** @todo reinstate this test when the issue is restored */ + case 'MethodSignatureMustProvideReturnType': + continue 2; + case 'InvalidFalsableReturnType': $ignored_issues = ['FalsableReturnStatement']; break; diff --git a/tests/MethodSignatureTest.php b/tests/MethodSignatureTest.php index 87c3bc71dbf..11f217b172f 100644 --- a/tests/MethodSignatureTest.php +++ b/tests/MethodSignatureTest.php @@ -1569,37 +1569,6 @@ public function bar(string ...$_args): void {} ', 'error_message' => 'MethodSignatureMismatch', ], - 'noMixedTypehintInDescendant' => [ - ' 'MethodSignatureMismatch', - [], - false, - '8.0' - ], - 'noTypehintInNativeDescendant' => [ - ' 'MethodSignatureMustProvideReturnType', - [], - false, - '8.1' - ], ]; } }