diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 58202505f72..8d205b058f7 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + @@ -1057,6 +1057,7 @@ + calling_function_id]]> diff --git a/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php index 4f0867f169d..49160c4bf8e 100644 --- a/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php @@ -257,6 +257,18 @@ public static function analyze( $statements_analyzer, null, ); + + [, $method_name] = explode('::', $cased_method_id); + if ($method_name === '__construct') { + IssueBuffer::maybeAdd( + new InvalidReturnStatement( + 'No return values are expected for ' . $cased_method_id, + new CodeLocation($source, $stmt->expr), + ), + $statements_analyzer->getSuppressedIssues(), + ); + return; + } } else { $declared_return_type = $storage->return_type; } diff --git a/tests/ReturnTypeTest.php b/tests/ReturnTypeTest.php index dff8fbc41be..64e79d442c3 100644 --- a/tests/ReturnTypeTest.php +++ b/tests/ReturnTypeTest.php @@ -1863,6 +1863,17 @@ function foo(bool $x): never 'ignored_issues' => [], 'php_version' => '8.1', ], + 'constructorsShouldReturnVoid' => [ + 'code' => <<<'PHP' + 'InvalidReturnStatement', + ], ]; } }