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:
parent
f2c82fa212
commit
050eb82f04
@ -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',
|
||||
|
@ -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'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user