Skip to content

Commit

Permalink
Fix #4210 - fix __invoke declaration tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Oct 7, 2020
1 parent 3f4096e commit a43e79f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php
Expand Up @@ -324,25 +324,29 @@ public static function getCallableFromAtomic(
);

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
);
}
}

Expand Down
16 changes: 16 additions & 0 deletions tests/CallableTest.php
Expand Up @@ -848,6 +848,22 @@ function foo($arg): void {}
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;
}'
],
];
}

Expand Down

0 comments on commit a43e79f

Please sign in to comment.