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

Always detect return type mismatches from docblock parents

This commit is contained in:
Brown 2020-09-07 16:42:25 -04:00
parent 4ffdbe0a21
commit 877a81f808
4 changed files with 19 additions and 2 deletions

View File

@ -361,14 +361,15 @@ class Populator
$declaring_method_storage->signature_return_type $declaring_method_storage->signature_return_type
) )
) { ) {
$method_storage->return_type = $declaring_method_storage->return_type; $method_storage->return_type = clone $declaring_method_storage->return_type;
$method_storage->inherited_return_type = true; $method_storage->inherited_return_type = true;
} elseif (UnionTypeComparator::isSimplyContainedBy( } elseif (UnionTypeComparator::isSimplyContainedBy(
$declaring_method_storage->return_type, $declaring_method_storage->return_type,
$method_storage->signature_return_type $method_storage->signature_return_type
)) { )) {
$method_storage->return_type = $declaring_method_storage->return_type; $method_storage->return_type = clone $declaring_method_storage->return_type;
$method_storage->inherited_return_type = true; $method_storage->inherited_return_type = true;
$method_storage->return_type->from_docblock = false;
} }
} }
} }

View File

@ -35,5 +35,7 @@ class GetClassMethodsReturnTypeProvider implements \Psalm\Plugin\Hook\FunctionRe
) { ) {
return Type::parseString('array<string>'); return Type::parseString('array<string>');
} }
return null;
} }
} }

View File

@ -35,5 +35,7 @@ class GetObjectVarsReturnTypeProvider implements \Psalm\Plugin\Hook\FunctionRetu
) { ) {
return Type::parseString('array<string, mixed>'); return Type::parseString('array<string, mixed>');
} }
return null;
} }
} }

View File

@ -1427,6 +1427,18 @@ class MethodSignatureTest extends TestCase
}', }',
'error_message' => 'ConstructorSignatureMismatch', 'error_message' => 'ConstructorSignatureMismatch',
], ],
'inheritDocblockReturnFromInterface' => [
'<?php
interface A {
/** @return ?string */
function foo();
}
class C implements A {
public function foo() : ?string {}
}',
'error_message' => 'InvalidReturnType',
],
]; ];
} }
} }