mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix analysis when __invoke() exists
This commit is contained in:
parent
46bcb626f5
commit
b9d8dd9d3f
@ -52,6 +52,7 @@ use Psalm\Type\Atomic\TLiteralString;
|
||||
use Psalm\Type\Atomic\TMixed;
|
||||
use Psalm\Type\Atomic\TNamedObject;
|
||||
use Psalm\Type\Atomic\TNull;
|
||||
use Psalm\Type\Atomic\TObjectWithProperties;
|
||||
use Psalm\Type\Atomic\TString;
|
||||
use Psalm\Type\Atomic\TTemplateParam;
|
||||
use Psalm\Type\Reconciler;
|
||||
@ -690,12 +691,11 @@ class FunctionCallAnalyzer extends CallAnalyzer
|
||||
);
|
||||
} elseif ($var_type_part instanceof TCallableObject
|
||||
|| $var_type_part instanceof TCallableString
|
||||
|| ($var_type_part instanceof TNamedObject && $var_type_part->value === 'Closure')
|
||||
|| ($var_type_part instanceof TObjectWithProperties && isset($var_type_part->methods['__invoke']))
|
||||
) {
|
||||
// this is fine
|
||||
$has_valid_function_call_type = true;
|
||||
} elseif (($var_type_part instanceof TNamedObject && $var_type_part->value === 'Closure')) {
|
||||
// this is fine
|
||||
$has_valid_function_call_type = true;
|
||||
} elseif ($var_type_part instanceof TString
|
||||
|| $var_type_part instanceof TArray
|
||||
|| $var_type_part instanceof TList
|
||||
|
@ -316,6 +316,15 @@ class CallableTest extends TestCase
|
||||
$c2 = new C();
|
||||
$c2();',
|
||||
],
|
||||
'invokeMethodExists' => [
|
||||
'<?php
|
||||
function call(object $obj): void {
|
||||
if (!method_exists($obj, "__invoke")) {
|
||||
return;
|
||||
}
|
||||
$obj();
|
||||
}',
|
||||
],
|
||||
'correctParamType' => [
|
||||
'<?php
|
||||
$take_string = function(string $s): string { return $s; };
|
||||
|
Loading…
Reference in New Issue
Block a user