diff --git a/src/Psalm/Checker/Statements/Expression/Call/MethodCallChecker.php b/src/Psalm/Checker/Statements/Expression/Call/MethodCallChecker.php index b8c7de0bb..40b895436 100644 --- a/src/Psalm/Checker/Statements/Expression/Call/MethodCallChecker.php +++ b/src/Psalm/Checker/Statements/Expression/Call/MethodCallChecker.php @@ -688,21 +688,23 @@ class MethodCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker if (count($lhs_types) === 1) { $method_storage = $codebase->methods->getUserMethodStorage($method_id); - if ($method_storage->assertions) { - self::applyAssertionsToContext( - $method_storage->assertions, - $args, - $context, - $statements_checker - ); - } + if ($method_storage) { + if ($method_storage->assertions) { + self::applyAssertionsToContext( + $method_storage->assertions, + $args, + $context, + $statements_checker + ); + } - if ($method_storage->if_true_assertions) { - $stmt->ifTrueAssertions = $method_storage->if_true_assertions; - } + if ($method_storage->if_true_assertions) { + $stmt->ifTrueAssertions = $method_storage->if_true_assertions; + } - if ($method_storage->if_false_assertions) { - $stmt->ifFalseAssertions = $method_storage->if_false_assertions; + if ($method_storage->if_false_assertions) { + $stmt->ifFalseAssertions = $method_storage->if_false_assertions; + } } } } diff --git a/src/Psalm/Checker/Statements/Expression/Call/StaticCallChecker.php b/src/Psalm/Checker/Statements/Expression/Call/StaticCallChecker.php index 2f8519eb3..630ac12ea 100644 --- a/src/Psalm/Checker/Statements/Expression/Call/StaticCallChecker.php +++ b/src/Psalm/Checker/Statements/Expression/Call/StaticCallChecker.php @@ -505,9 +505,9 @@ class StaticCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker } } - try { - $method_storage = $codebase->methods->getUserMethodStorage($method_id); + $method_storage = $codebase->methods->getUserMethodStorage($method_id); + if ($method_storage) { if ($method_storage->assertions) { self::applyAssertionsToContext( $method_storage->assertions, @@ -524,8 +524,6 @@ class StaticCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker if ($method_storage->if_false_assertions) { $stmt->ifFalseAssertions = $method_storage->if_false_assertions; } - } catch (\UnexpectedValueException $e) { - // do nothing for non-user-defined methods } if ($config->after_method_checks) { diff --git a/src/Psalm/Codebase/Methods.php b/src/Psalm/Codebase/Methods.php index 40f0fa9e1..79e2b0f22 100644 --- a/src/Psalm/Codebase/Methods.php +++ b/src/Psalm/Codebase/Methods.php @@ -535,7 +535,7 @@ class Methods /** * @param string $method_id * - * @return MethodStorage + * @return ?MethodStorage */ public function getUserMethodStorage($method_id) { @@ -548,7 +548,7 @@ class Methods $storage = $this->getStorage($declaring_method_id); if (!$storage->location) { - throw new \UnexpectedValueException('Storage for ' . $method_id . ' is not user-defined'); + return null; } return $storage;