Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/Rules/Comparison/ImpossibleCheckTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeTraverser;
use PHPStan\Type\TypeUtils;
use PHPStan\Type\TypeWithClassName;
use PHPStan\Type\UnionType;
use PHPStan\Type\VerbosityLevel;
Expand Down Expand Up @@ -428,7 +427,7 @@ private function determineContext(Scope $scope, Expr $node): TypeSpecifierContex
if ($this->reflectionProvider->hasFunction($node->name, $scope)) {
$functionReflection = $this->reflectionProvider->getFunction($node->name, $scope);
$parametersAcceptor = ParametersAcceptorSelector::selectFromArgs($scope, $node->getArgs(), $functionReflection->getVariants(), $functionReflection->getNamedArgumentsVariants());
$returnType = TypeUtils::resolveLateResolvableTypes($parametersAcceptor->getReturnType());
$returnType = $parametersAcceptor->getReturnType();
Copy link
Contributor Author

@staabm staabm Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my initial idea which made me visit this code was, whether we can cache the TypeSpecifierContext per CallLike, in case its a native non-conditional return type of a single-variant callable.

turns out I cannot detect at this level whether the return type is conditional, because its already resolved.

any idea how I could do it instead?

update: found a way #4817


return $returnType->isVoid()->yes() ? TypeSpecifierContext::createNull() : TypeSpecifierContext::createTruthy();
}
Expand All @@ -437,7 +436,7 @@ private function determineContext(Scope $scope, Expr $node): TypeSpecifierContex
$methodReflection = $scope->getMethodReflection($methodCalledOnType, $node->name->name);
if ($methodReflection !== null) {
$parametersAcceptor = ParametersAcceptorSelector::selectFromArgs($scope, $node->getArgs(), $methodReflection->getVariants(), $methodReflection->getNamedArgumentsVariants());
$returnType = TypeUtils::resolveLateResolvableTypes($parametersAcceptor->getReturnType());
$returnType = $parametersAcceptor->getReturnType();

return $returnType->isVoid()->yes() ? TypeSpecifierContext::createNull() : TypeSpecifierContext::createTruthy();
}
Expand All @@ -451,7 +450,7 @@ private function determineContext(Scope $scope, Expr $node): TypeSpecifierContex
$staticMethodReflection = $scope->getMethodReflection($calleeType, $node->name->name);
if ($staticMethodReflection !== null) {
$parametersAcceptor = ParametersAcceptorSelector::selectFromArgs($scope, $node->getArgs(), $staticMethodReflection->getVariants(), $staticMethodReflection->getNamedArgumentsVariants());
$returnType = TypeUtils::resolveLateResolvableTypes($parametersAcceptor->getReturnType());
$returnType = $parametersAcceptor->getReturnType();

return $returnType->isVoid()->yes() ? TypeSpecifierContext::createNull() : TypeSpecifierContext::createTruthy();
}
Expand Down
Loading