1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Always evaluate static calls when method call cannot

This commit is contained in:
Brown 2019-04-18 13:51:34 -04:00
parent 50035334d4
commit 4807ebe04a
3 changed files with 114 additions and 99 deletions

View File

@ -174,7 +174,10 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
$no_method_id = false;
if ($class_type) {
if (!$class_type) {
$class_type = Type::getMixed();
}
$return_type = null;
$lhs_types = $class_type->getTypes();
@ -302,7 +305,6 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
$stmt->inferredType->by_ref = $returns_by_ref;
}
}
if ($no_method_id) {
return self::checkMethodArgs(
@ -334,7 +336,7 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
// if we called a method on this nullable variable, remove the nullable status here
// because any further calls must have worked
if ($lhs_var_id
&& $class_type
&& !$class_type->isMixed()
&& $has_valid_method_call_type
&& !$has_mixed_method_call
&& !$invalid_method_call_types

View File

@ -370,6 +370,7 @@ class CallAnalyzer
|| $arg->value instanceof PhpParser\Node\Expr\ConstFetch
|| $arg->value instanceof PhpParser\Node\Expr\FuncCall
|| $arg->value instanceof PhpParser\Node\Expr\MethodCall
|| $arg->value instanceof PhpParser\Node\Expr\StaticCall
|| $arg->value instanceof PhpParser\Node\Expr\Assign
|| $arg->value instanceof PhpParser\Node\Expr\Array_
)
@ -448,6 +449,7 @@ class CallAnalyzer
|| $arg->value instanceof PhpParser\Node\Expr\ConstFetch
|| $arg->value instanceof PhpParser\Node\Expr\FuncCall
|| $arg->value instanceof PhpParser\Node\Expr\MethodCall
|| $arg->value instanceof PhpParser\Node\Expr\StaticCall
|| $arg->value instanceof PhpParser\Node\Expr\Assign
|| $arg->value instanceof PhpParser\Node\Expr\ArrayDimFetch
|| $arg->value instanceof PhpParser\Node\Expr\Array_
@ -1278,6 +1280,7 @@ class CallAnalyzer
$arg->value instanceof PhpParser\Node\Expr\ConstFetch
|| $arg->value instanceof PhpParser\Node\Expr\FuncCall
|| $arg->value instanceof PhpParser\Node\Expr\MethodCall
|| $arg->value instanceof PhpParser\Node\Expr\StaticCall
) && (
!isset($arg->value->inferredType)
|| !$arg->value->inferredType->by_ref

View File

@ -577,6 +577,16 @@ class MethodCallTest extends TestCase
}',
'error_message' => 'UndefinedClass',
],
'checkMixedMethodCallStaticMethodCallArg' => [
'<?php
class B {}
/** @param mixed $a */
function foo($a) : void {
/** @psalm-suppress MixedMethodCall */
$a->bar(B::bat());
}',
'error_message' => 'UndefinedMethod',
],
];
}
}