Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "PHP 8.1: Report missing typehints in overridden native methods" #7539

Merged
merged 4 commits into from Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -8,7 +8,6 @@ This issue is emitted when a method overriding a native method is defined withou

```php
<?php

class A implements JsonSerializable {
public function jsonSerialize() {
return ['type' => 'A'];
Expand Down
10 changes: 9 additions & 1 deletion psalm-baseline.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.x-dev@64206d9c3a9723bba093beb7d1a77ee767332d8a">
<files psalm-version="4.x-dev@603714518b3894a57b464920b906a13332f23c02">
<file src="examples/TemplateChecker.php">
<PossiblyUndefinedIntArrayOffset occurrences="2">
<code>$comment_block-&gt;tags['variablesfrom'][0]</code>
Expand All @@ -21,6 +21,9 @@
<code>$matches[0]</code>
<code>$symbol_parts[1]</code>
</PossiblyUndefinedIntArrayOffset>
<PossiblyUnusedProperty occurrences="1">
<code>$analysis_php_version_id</code>
</PossiblyUnusedProperty>
</file>
<file src="src/Psalm/Config.php">
<DeprecatedMethod occurrences="3">
Expand Down Expand Up @@ -659,6 +662,11 @@
<code>array_keys($template_type_map[$template_param_name])[0]</code>
</PossiblyUndefinedIntArrayOffset>
</file>
<file src="src/Psalm/Issue/MethodSignatureMustProvideReturnType.php">
<UnusedClass occurrences="1">
<code>MethodSignatureMustProvideReturnType</code>
</UnusedClass>
</file>
<file src="src/Psalm/Node/Stmt/VirtualClass.php">
<PropertyNotSetInConstructor occurrences="1">
<code>VirtualClass</code>
Expand Down
35 changes: 1 addition & 34 deletions src/Psalm/Internal/Analyzer/MethodComparator.php
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tests/DocumentationTest.php
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 0 additions & 31 deletions tests/MethodSignatureTest.php
Expand Up @@ -1569,37 +1569,6 @@ public function bar(string ...$_args): void {}
',
'error_message' => 'MethodSignatureMismatch',
],
'noMixedTypehintInDescendant' => [
'<?php
class a {
public function test(): mixed {
return 0;
}
}
class b extends a {
public function test() {
return 0;
}
}
',
'error_message' => 'MethodSignatureMismatch',
[],
false,
'8.0'
],
'noTypehintInNativeDescendant' => [
'<?php
class a implements JsonSerializable {
public function jsonSerialize() {
return 0;
}
}
',
'error_message' => 'MethodSignatureMustProvideReturnType',
[],
false,
'8.1'
],
];
}
}