1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Allow compounding method_exists types with ||

This commit is contained in:
Matthew Brown 2019-08-20 00:00:20 -04:00
parent 17e7fe70c1
commit 73f245f91d
2 changed files with 23 additions and 1 deletions

View File

@ -848,7 +848,7 @@ class AssertionReconciler extends \Psalm\Type\Reconciler
}
}
if (!$object_types || !$did_remove_type) {
if (!$object_types) {
if ($key && $code_location) {
self::triggerIssueForImpossible(
$existing_var_type,

View File

@ -379,6 +379,15 @@ class MethodCallTest extends TestCase
$object->bar();
}'
],
'callManyMethodsAfterCheckingExistenceChained' => [
'<?php
function foo(object $object) : void {
if (method_exists($object, "foo") && method_exists($object, "bar")) {
$object->foo();
$object->bar();
}
}'
],
];
}
@ -651,6 +660,19 @@ class MethodCallTest extends TestCase
}',
'error_message' => 'UndefinedThisPropertyFetch',
],
'alreadyHasmethod' => [
'<?php
class A {
public function foo() : void {}
}
function foo(A $a) : void {
if (method_exists($a, "foo")) {
$object->foo();
}
}',
'error_message' => 'RedundantCondition',
],
];
}
}