From 52c414f1d2b8927c5e791c4ff169209b6c6bbd3e Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Thu, 14 Dec 2017 12:50:02 -0500 Subject: [PATCH] Fix return {expr} checks for void functions --- src/Psalm/Checker/SourceChecker.php | 4 ++-- src/Psalm/Checker/StatementsChecker.php | 4 ++++ tests/ReturnTypeTest.php | 9 +++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Checker/SourceChecker.php b/src/Psalm/Checker/SourceChecker.php index 2ef9080f9..6627e11a0 100644 --- a/src/Psalm/Checker/SourceChecker.php +++ b/src/Psalm/Checker/SourceChecker.php @@ -172,7 +172,7 @@ abstract class SourceChecker implements StatementsSource throw new \UnexpectedValueException('$source cannot be null'); } - return $this->source->addSuppressedIssues($new_issues); + $this->source->addSuppressedIssues($new_issues); } /** @@ -186,7 +186,7 @@ abstract class SourceChecker implements StatementsSource throw new \UnexpectedValueException('$source cannot be null'); } - return $this->source->removeSuppressedIssues($new_issues); + $this->source->removeSuppressedIssues($new_issues); } /** diff --git a/src/Psalm/Checker/StatementsChecker.php b/src/Psalm/Checker/StatementsChecker.php index d525abb61..a10169439 100644 --- a/src/Psalm/Checker/StatementsChecker.php +++ b/src/Psalm/Checker/StatementsChecker.php @@ -908,6 +908,10 @@ class StatementsChecker extends SourceChecker implements StatementsSource $stmt->inferredType = Type::parseString($var_comment->type); } elseif (isset($stmt->expr->inferredType)) { $stmt->inferredType = $stmt->expr->inferredType; + + if ($stmt->inferredType->isVoid()) { + $stmt->inferredType = Type::getNull(); + } } else { $stmt->inferredType = Type::getMixed(); } diff --git a/tests/ReturnTypeTest.php b/tests/ReturnTypeTest.php index 8fc6a39d5..68ace9b04 100644 --- a/tests/ReturnTypeTest.php +++ b/tests/ReturnTypeTest.php @@ -538,6 +538,15 @@ class ReturnTypeTest extends TestCase }', 'error_message' => 'ReservedWord', ], + 'disallowReturningExplicitVoid' => [ + ' 'InvalidReturnStatement', + ], ]; } }