1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #2290 - detect call on void type

This commit is contained in:
Matthew Brown 2019-11-01 13:05:28 +00:00
parent f2c82fa212
commit 050eb82f04
2 changed files with 14 additions and 1 deletions

View File

@ -140,7 +140,10 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
$has_mock = false;
if ($class_type && $stmt->name instanceof PhpParser\Node\Identifier && $class_type->isNull()) {
if ($class_type
&& $stmt->name instanceof PhpParser\Node\Identifier
&& ($class_type->isNull() || $class_type->isVoid())
) {
if (IssueBuffer::accepts(
new NullReference(
'Cannot call method ' . $stmt->name->name . ' on null value',

View File

@ -731,6 +731,16 @@ class MethodCallTest extends TestCase
}',
'error_message' => 'PossiblyNullArgument',
],
'callOnVoid' => [
'<?php
class A {
public function foo(): void {}
}
$p = new A();
$p->foo()->bar();',
'error_message' => 'NullReference'
],
];
}
}