mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Fix #2294 - detect invalid callble due to __invoke
This commit is contained in:
parent
64996f464e
commit
86b6801066
@ -1683,6 +1683,21 @@ class TypeAnalyzer
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
} elseif ($input_type_part instanceof TNamedObject
|
||||
&& $codebase->classExists($input_type_part->value)
|
||||
&& $codebase->methodExists($input_type_part->value . '::__invoke')
|
||||
) {
|
||||
return new TCallable(
|
||||
'callable',
|
||||
$codebase->getMethodParams(
|
||||
$input_type_part->value . '::__invoke'
|
||||
),
|
||||
$codebase->getMethodReturnType(
|
||||
$input_type_part->value . '::__invoke',
|
||||
$input_type_part->value,
|
||||
[]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -1203,6 +1203,34 @@ class FunctionTemplateTest extends TestCase
|
||||
makeResultSet([A::class, "returnsObjectOrNull"]);',
|
||||
'error_message' => 'InvalidArgument',
|
||||
],
|
||||
'templateInvokeArg' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template T
|
||||
* @param callable(T):void $c
|
||||
* @param T $param
|
||||
*/
|
||||
function apply(callable $c, $param):void{
|
||||
call_user_func($c, $param);
|
||||
}
|
||||
|
||||
class A {
|
||||
public function __toString(){
|
||||
return "a";
|
||||
}
|
||||
}
|
||||
|
||||
class B {}
|
||||
|
||||
class Printer{
|
||||
public function __invoke(A $a) : void {
|
||||
echo $a;
|
||||
}
|
||||
}
|
||||
|
||||
apply(new Printer(), new B());',
|
||||
'error_message' => 'InvalidArgument'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user