1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 12:24:49 +01:00

Fix #4210 - fix __invoke declaration tracing

This commit is contained in:
Brown 2020-09-19 14:18:52 -04:00 committed by Daniil Gentili
parent 93d66117d0
commit 1b6ecfc128
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 37 additions and 17 deletions

View File

@ -324,25 +324,29 @@ class CallableTypeComparator
);
if ($codebase->methods->methodExists($invoke_id)) {
$method_storage = $codebase->methods->getStorage($invoke_id);
$method_fqcln = $invoke_id->fq_class_name;
$converted_return_type = null;
if ($method_storage->return_type) {
$converted_return_type = \Psalm\Internal\Type\TypeExpander::expandUnion(
$codebase,
$method_storage->return_type,
$method_fqcln,
$method_fqcln,
null
$declaring_method_id = $codebase->methods->getDeclaringMethodId($invoke_id);
if ($declaring_method_id) {
$method_storage = $codebase->methods->getStorage($declaring_method_id);
$method_fqcln = $invoke_id->fq_class_name;
$converted_return_type = null;
if ($method_storage->return_type) {
$converted_return_type = \Psalm\Internal\Type\TypeExpander::expandUnion(
$codebase,
$method_storage->return_type,
$method_fqcln,
$method_fqcln,
null
);
}
return new TCallable(
'callable',
$method_storage->params,
$converted_return_type,
$method_storage->pure
);
}
return new TCallable(
'callable',
$method_storage->params,
$converted_return_type,
$method_storage->pure
);
}
}

View File

@ -848,6 +848,22 @@ class CallableTest extends TestCase
foo(["a", "b"]);'
],
'abstractInvokeInTrait' => [
'<?php
function testFunc(callable $func) : void {}
trait TestTrait {
abstract public function __invoke() : void;
public function apply() : void {
testFunc($this);
}
}
abstract class TestClass {
use TestTrait;
}'
],
];
}