From 67d995b67f6755a624256c78dd7e52a69415c664 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Sun, 4 Oct 2020 23:39:08 -0400 Subject: [PATCH] 4.x - Prevent AfterFunctionCallAnalysisInterface from rewriting return types --- examples/plugins/FunctionCasingChecker.php | 4 ++-- .../Statements/Expression/Call/FunctionCallAnalyzer.php | 8 ++------ .../Plugin/Hook/AfterFunctionCallAnalysisInterface.php | 4 ++-- tests/fixtures/stubs/base_plugin.php | 4 ++-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/examples/plugins/FunctionCasingChecker.php b/examples/plugins/FunctionCasingChecker.php index 77d466257..58130b6b5 100644 --- a/examples/plugins/FunctionCasingChecker.php +++ b/examples/plugins/FunctionCasingChecker.php @@ -83,8 +83,8 @@ class FunctionCasingChecker implements AfterFunctionCallAnalysisInterface, After Context $context, StatementsSource $statements_source, Codebase $codebase, - array &$file_replacements = [], - Union &$return_type_candidate = null + Union $return_type_candidate, + array &$file_replacements ) { if ($expr->name instanceof PhpParser\Node\Expr) { return; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php index ef4882522..8333cd87d 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php @@ -1002,8 +1002,8 @@ class FunctionCallAnalyzer extends CallAnalyzer $context, $statements_analyzer->getSource(), $codebase, - $file_manipulations, - $return_type + $return_type, + $file_manipulations ); } @@ -1015,10 +1015,6 @@ class FunctionCallAnalyzer extends CallAnalyzer } } - if ($return_type === null) { - throw new \UnexpectedValueException('$return_type shouldn’t be null here'); - } - $stmt_type = $return_type; $return_type->by_ref = $function_storage->returns_by_ref; diff --git a/src/Psalm/Plugin/Hook/AfterFunctionCallAnalysisInterface.php b/src/Psalm/Plugin/Hook/AfterFunctionCallAnalysisInterface.php index 3d5ccd1e7..35b1a0a8a 100644 --- a/src/Psalm/Plugin/Hook/AfterFunctionCallAnalysisInterface.php +++ b/src/Psalm/Plugin/Hook/AfterFunctionCallAnalysisInterface.php @@ -22,7 +22,7 @@ interface AfterFunctionCallAnalysisInterface Context $context, StatementsSource $statements_source, Codebase $codebase, - array &$file_replacements = [], - Union &$return_type_candidate = null + Union $return_type_candidate, + array &$file_replacements ); } diff --git a/tests/fixtures/stubs/base_plugin.php b/tests/fixtures/stubs/base_plugin.php index b84d00de7..6c447bd9d 100644 --- a/tests/fixtures/stubs/base_plugin.php +++ b/tests/fixtures/stubs/base_plugin.php @@ -8,8 +8,8 @@ class BasePlugin implements Psalm\Plugin\Hook\AfterFunctionCallAnalysisInterface \Psalm\Context $context, \Psalm\StatementsSource $statements_source, \Psalm\Codebase $codebase, - array &$file_replacements = [], - \Psalm\Type\Union &$return_type_candidate = null + \Psalm\Type\Union &$return_type_candidate, + array &$file_replacements ) { } }