1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Improve abstract call handling

This commit is contained in:
Matthew Brown 2020-03-11 10:36:39 -04:00
parent 27598f508e
commit ef64e6e8eb
2 changed files with 15 additions and 3 deletions

View File

@ -11,7 +11,7 @@ new A();
### AbstractMethodCall
Emitted when an attempt is made to call an abstract method
Emitted when an attempt is made to call an abstract static method directly
```php
abstract class Base {

View File

@ -953,10 +953,22 @@ class StaticCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
$method_storage = $codebase->methods->getUserMethodStorage($method_id);
if ($method_storage) {
if ($method_storage->abstract) {
if ($method_storage->abstract
&& (!$context->self
|| !\Psalm\Internal\Analyzer\TypeAnalyzer::isContainedBy(
$codebase,
$context->vars_in_scope['$this']
?? new Type\Union([
new Type\Atomic\TNamedObject($context->self)
]),
new Type\Union([
new Type\Atomic\TNamedObject($method_id->fq_class_name)
])
))
) {
if (IssueBuffer::accepts(
new AbstractMethodCall(
'Cannot call an abstract method ' . $method_id,
'Cannot call an abstract static method ' . $method_id . ' directly',
new CodeLocation($statements_analyzer->getSource(), $stmt)
),
$statements_analyzer->getSuppressedIssues()