mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Support existing concatenation more better
This commit is contained in:
parent
73f245f91d
commit
302ed4b21b
@ -820,12 +820,34 @@ class AssertionReconciler extends \Psalm\Type\Reconciler
|
||||
$object_types[] = $type;
|
||||
|
||||
if (!$codebase->methodExists($type->value . '::' . $method_name)) {
|
||||
$obj = new Atomic\TObjectWithProperties(
|
||||
[],
|
||||
[$method_name => $type->value . '::' . $method_name]
|
||||
);
|
||||
$type->extra_types[$obj->getKey()] = $obj;
|
||||
$did_remove_type = true;
|
||||
$match_found = false;
|
||||
|
||||
if ($type->extra_types) {
|
||||
foreach ($type->extra_types as $extra_type) {
|
||||
if ($extra_type instanceof TNamedObject
|
||||
&& $codebase->classOrInterfaceExists($extra_type->value)
|
||||
&& $codebase->methodExists($extra_type->value . '::' . $method_name)
|
||||
) {
|
||||
$match_found = true;
|
||||
} elseif ($extra_type instanceof Atomic\TObjectWithProperties) {
|
||||
$match_found = true;
|
||||
|
||||
if (!isset($extra_type->methods[$method_name])) {
|
||||
$extra_type->methods[$method_name] = 'object::' . $method_name;
|
||||
$did_remove_type = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$match_found) {
|
||||
$obj = new Atomic\TObjectWithProperties(
|
||||
[],
|
||||
[$method_name => $type->value . '::' . $method_name]
|
||||
);
|
||||
$type->extra_types[$obj->getKey()] = $obj;
|
||||
$did_remove_type = true;
|
||||
}
|
||||
}
|
||||
} elseif ($type instanceof Atomic\TObjectWithProperties) {
|
||||
$object_types[] = $type;
|
||||
|
@ -388,6 +388,16 @@ class MethodCallTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'callManyMethodsOnKnownObjectAfterCheckingExistenceChained' => [
|
||||
'<?php
|
||||
class A {}
|
||||
function foo(A $object) : void {
|
||||
if (method_exists($object, "foo") && method_exists($object, "bar")) {
|
||||
$object->foo();
|
||||
$object->bar();
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user