Skip to content

Commit 893813c

Browse files
committed
Php8SignatureMapProvider - prefer functionMap return type if PHP 8 stub file has only PHPDoc
1 parent 75d00c9 commit 893813c

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/Reflection/SignatureMap/Php8SignatureMapProvider.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,21 @@ private function mergeSignatures(FunctionSignature $nativeSignature, FunctionSig
207207
}
208208

209209
$nativeReturnType = $nativeSignature->getNativeReturnType();
210-
211-
return new FunctionSignature(
212-
$parameters,
213-
TypehintHelper::decideType(
210+
if ($nativeReturnType instanceof MixedType && !$nativeReturnType->isExplicitMixed()) {
211+
$returnType = $functionMapSignature->getReturnType();
212+
} else {
213+
$returnType = TypehintHelper::decideType(
214214
$nativeReturnType,
215215
TypehintHelper::decideType(
216216
$nativeSignature->getReturnType(),
217217
$functionMapSignature->getReturnType()
218218
)
219-
),
219+
);
220+
}
221+
222+
return new FunctionSignature(
223+
$parameters,
224+
$returnType,
220225
$nativeReturnType,
221226
$nativeSignature->isVariadic()
222227
);

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10526,6 +10526,11 @@ public function dataBugEmptyArray(): array
1052610526
return $this->gatherAssertTypes(__DIR__ . '/data/bug-empty-array.php');
1052710527
}
1052810528

10529+
public function dataBug4205(): array
10530+
{
10531+
return $this->gatherAssertTypes(__DIR__ . '/data/bug-4205.php');
10532+
}
10533+
1052910534
/**
1053010535
* @param string $file
1053110536
* @return array<string, mixed[]>
@@ -10717,6 +10722,7 @@ private function gatherAssertTypes(string $file): array
1071710722
* @dataProvider dataBug4207
1071810723
* @dataProvider dataBug4206
1071910724
* @dataProvider dataBugEmptyArray
10725+
* @dataProvider dataBug4205
1072010726
* @param string $assertType
1072110727
* @param string $file
1072210728
* @param mixed ...$args
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Bug4205;
4+
5+
use function PHPStan\Analyser\assertType;
6+
7+
function () {
8+
$result = set_error_handler(function() {}, E_ALL);
9+
assertType('(callable(): mixed)|null', $result);
10+
};

0 commit comments

Comments
 (0)