diff --git a/psalm-baseline.xml b/psalm-baseline.xml index d192f9eb061..dbdec1f11d2 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1054,6 +1054,7 @@ + calling_function_id]]> diff --git a/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php index 945dfd60d1f..ec109d6b84c 100644 --- a/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php @@ -277,6 +277,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/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php index b91b521ec88..bebfb1026ee 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php @@ -804,7 +804,9 @@ private function getTranslatedFunctionParam( $this->codebase->analysis_php_version_id, ); - if ($is_nullable) { + if ($param_type->isMixed()) { + $is_nullable = false; + } elseif ($is_nullable) { $param_type = $param_type->getBuilder()->addType(new TNull)->freeze(); } else { $is_nullable = $param_type->isNullable(); diff --git a/tests/ArgTest.php b/tests/ArgTest.php index 93e7f022d68..ce75f65c15c 100644 --- a/tests/ArgTest.php +++ b/tests/ArgTest.php @@ -357,6 +357,20 @@ function foo($a, ...$b) {} var_caller("foo");', ], + 'mixedNullable' => [ + 'code' => 'default;', + 'assertions' => [ + '$_v===' => 'mixed', + ], + 'ignored_issues' => [], + 'php_version' => '8.0', + ], ]; } diff --git a/tests/ReturnTypeTest.php b/tests/ReturnTypeTest.php index 842a79bdb37..2273bb98c7f 100644 --- a/tests/ReturnTypeTest.php +++ b/tests/ReturnTypeTest.php @@ -1914,6 +1914,17 @@ function foo(bool $x): never 'ignored_issues' => [], 'php_version' => '8.1', ], + 'constructorsShouldReturnVoid' => [ + 'code' => <<<'PHP' + 'InvalidReturnStatement', + ], ]; } }