From 950260a041d6afc00ae31753a9f5d0e24b1a10fc Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Wed, 11 Mar 2020 18:27:07 -0400 Subject: [PATCH] No erroneous UndefinedMethod when accessing sealed class --- .../Call/AtomicMethodCallAnalyzer.php | 26 +++++++++---------- tests/MagicMethodAnnotationTest.php | 15 +++++++++++ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/AtomicMethodCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/AtomicMethodCallAnalyzer.php index 43a9ca35c..bfd030c3b 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/AtomicMethodCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/AtomicMethodCallAnalyzer.php @@ -173,7 +173,6 @@ class AtomicMethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expre } if (!$does_class_exist) { - $result->non_existent_class_method_ids[] = $fq_class_name . '::*'; return; } @@ -821,17 +820,15 @@ class AtomicMethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expre $pseudo_method_storage = $class_storage->pseudo_methods[$method_name_lc]; - if (self::checkFunctionArguments( + self::checkFunctionArguments( $statements_analyzer, $stmt->args, $pseudo_method_storage->params, (string) $method_id, $context - ) === false) { - return null; - } + ); - if (self::checkFunctionLikeArgumentsMatch( + self::checkFunctionLikeArgumentsMatch( $statements_analyzer, $stmt->args, null, @@ -841,9 +838,7 @@ class AtomicMethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expre null, new CodeLocation($statements_analyzer, $stmt), $context - ) === false) { - return null; - } + ); if ($pseudo_method_storage->return_type) { $return_type_candidate = clone $pseudo_method_storage->return_type; @@ -879,20 +874,23 @@ class AtomicMethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expre ); } } else { - if (self::checkFunctionArguments( + self::checkFunctionArguments( $statements_analyzer, $stmt->args, null, null, $context - ) === false) { - return null; - } + ); if ($class_storage->sealed_methods) { $result->non_existent_magic_method_ids[] = $method_id; - return null; } + + return new AtomicCallContext( + $method_id, + $stmt->args, + $statements_analyzer->node_data + ); } $result->has_valid_method_call_type = true; diff --git a/tests/MagicMethodAnnotationTest.php b/tests/MagicMethodAnnotationTest.php index fa68e8a02..9c467e6a0 100644 --- a/tests/MagicMethodAnnotationTest.php +++ b/tests/MagicMethodAnnotationTest.php @@ -583,6 +583,21 @@ class MagicMethodAnnotationTest extends TestCase */ class Foo {}' ], + 'annotationWithSealedSuppressingUndefinedMagicMethod' => [ + 'foo();' + ], ]; }