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

Fix issue calling possibly magic method

This commit is contained in:
Matthew Brown 2018-08-02 16:14:53 -05:00
parent c9a2ca9321
commit 37be70a465
2 changed files with 20 additions and 5 deletions

View File

@ -93,12 +93,10 @@ class MethodCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker
$source = $statements_checker->getSource();
$args = $stmt->args;
if (!$context->check_methods || !$context->check_classes) {
if (self::checkFunctionArguments(
$statements_checker,
$args,
$stmt->args,
null,
null,
$context
@ -219,7 +217,7 @@ class MethodCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker
if (self::checkFunctionArguments(
$statements_checker,
$args,
$stmt->args,
null,
null,
$context
@ -301,6 +299,8 @@ class MethodCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker
? '(' . $lhs_type_part . ')' . '::' . $stmt->name->name
: null;
$args = $stmt->args;
if ($codebase->methodExists($fq_class_name . '::__call')) {
if (!$codebase->methodExists($method_id)
|| !MethodChecker::isMethodVisible(
@ -806,7 +806,7 @@ class MethodCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker
if ($method_id === null) {
return self::checkMethodArgs(
$method_id,
$args,
$stmt->args,
$found_generic_params,
$context,
new CodeLocation($statements_checker->getSource(), $stmt),

View File

@ -105,6 +105,21 @@ class MethodCallTest extends TestCase
'assertions' => [],
'error_levels' => ['PossiblyUndefinedMethod'],
],
'canBeCalledOnMagicWithMethod' => [
'<?php
class A {
public function __call(string $method, array $args) {}
}
class B {
public function bar() : void {}
}
$a = rand(0, 1) ? new A : new B;
$a->bar();',
'assertions' => [],
],
'invokeCorrectType' => [
'<?php
class A {