mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Always detect return type mismatches from docblock parents
This commit is contained in:
parent
4ffdbe0a21
commit
877a81f808
@ -361,14 +361,15 @@ class Populator
|
||||
$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;
|
||||
} elseif (UnionTypeComparator::isSimplyContainedBy(
|
||||
$declaring_method_storage->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->return_type->from_docblock = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,5 +35,7 @@ class GetClassMethodsReturnTypeProvider implements \Psalm\Plugin\Hook\FunctionRe
|
||||
) {
|
||||
return Type::parseString('array<string>');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -35,5 +35,7 @@ class GetObjectVarsReturnTypeProvider implements \Psalm\Plugin\Hook\FunctionRetu
|
||||
) {
|
||||
return Type::parseString('array<string, mixed>');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1427,6 +1427,18 @@ class MethodSignatureTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'ConstructorSignatureMismatch',
|
||||
],
|
||||
'inheritDocblockReturnFromInterface' => [
|
||||
'<?php
|
||||
interface A {
|
||||
/** @return ?string */
|
||||
function foo();
|
||||
}
|
||||
|
||||
class C implements A {
|
||||
public function foo() : ?string {}
|
||||
}',
|
||||
'error_message' => 'InvalidReturnType',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user