From fcf0a681d94e97a8a329a0aa8d66a68f900a16b2 Mon Sep 17 00:00:00 2001 From: Brown Date: Sat, 6 Jun 2020 10:33:49 -0400 Subject: [PATCH] Fix #3531 - ignore mixed returns from template --- .../Analyzer/Statements/ReturnAnalyzer.php | 4 ++++ tests/Template/ClassTemplateExtendsTest.php | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php index d6fc70af7..cfdb3952b 100644 --- a/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php @@ -289,6 +289,10 @@ class ReturnAnalyzer return null; } + if ($local_return_type->isMixed()) { + return null; + } + if (!$context->collect_initializations && !$context->collect_mutations && $statements_analyzer->getFilePath() === $statements_analyzer->getRootFilePath() diff --git a/tests/Template/ClassTemplateExtendsTest.php b/tests/Template/ClassTemplateExtendsTest.php index d01d8da1a..71a0644c5 100644 --- a/tests/Template/ClassTemplateExtendsTest.php +++ b/tests/Template/ClassTemplateExtendsTest.php @@ -4114,6 +4114,30 @@ class ClassTemplateExtendsTest extends TestCase takesSubjects($subjects); }' ], + 'implementMixedReturnNull' => [ + 't = $t; + } + + public function foo() { + if (rand(0, 1)) { + return null; + } + + return $this->t; + } + }' + ], ]; }