diff --git a/src/Reflection/SignatureMap/Php8SignatureMapProvider.php b/src/Reflection/SignatureMap/Php8SignatureMapProvider.php index 44b88c873a..86be50426a 100644 --- a/src/Reflection/SignatureMap/Php8SignatureMapProvider.php +++ b/src/Reflection/SignatureMap/Php8SignatureMapProvider.php @@ -207,16 +207,21 @@ private function mergeSignatures(FunctionSignature $nativeSignature, FunctionSig } $nativeReturnType = $nativeSignature->getNativeReturnType(); - - return new FunctionSignature( - $parameters, - TypehintHelper::decideType( + if ($nativeReturnType instanceof MixedType && !$nativeReturnType->isExplicitMixed()) { + $returnType = $functionMapSignature->getReturnType(); + } else { + $returnType = TypehintHelper::decideType( $nativeReturnType, TypehintHelper::decideType( $nativeSignature->getReturnType(), $functionMapSignature->getReturnType() ) - ), + ); + } + + return new FunctionSignature( + $parameters, + $returnType, $nativeReturnType, $nativeSignature->isVariadic() ); diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index 94f3acd1a9..e1ed374d22 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -10526,6 +10526,11 @@ public function dataBugEmptyArray(): array return $this->gatherAssertTypes(__DIR__ . '/data/bug-empty-array.php'); } + public function dataBug4205(): array + { + return $this->gatherAssertTypes(__DIR__ . '/data/bug-4205.php'); + } + /** * @param string $file * @return array @@ -10717,6 +10722,7 @@ private function gatherAssertTypes(string $file): array * @dataProvider dataBug4207 * @dataProvider dataBug4206 * @dataProvider dataBugEmptyArray + * @dataProvider dataBug4205 * @param string $assertType * @param string $file * @param mixed ...$args diff --git a/tests/PHPStan/Analyser/data/bug-4205.php b/tests/PHPStan/Analyser/data/bug-4205.php new file mode 100644 index 0000000000..48e88511fd --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-4205.php @@ -0,0 +1,10 @@ +