Skip to content

Commit 65815bd

Browse files
phpstan-botclaude
authored andcommitted
Fix instance method calls on non-generic class-string returning ErrorType
Apply the same fix from StaticCallHandler to MethodCallHandler: when methodCallReturnType returns null and the resolved type is a classless object (from plain class-string), return MixedType instead of ErrorType. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1f4476f commit 65815bd

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/Analyser/ExprHandler/MethodCallHandler.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,27 +288,35 @@ public function resolveType(MutatingScope $scope, Expr $expr): Type
288288
{
289289
if ($expr->name instanceof Identifier) {
290290
if ($scope->nativeTypesPromoted) {
291+
$nativeType = $scope->getNativeType($expr->var);
291292
$methodReflection = $scope->getMethodReflection(
292-
$scope->getNativeType($expr->var),
293+
$nativeType,
293294
$expr->name->name,
294295
);
295296
if ($methodReflection === null) {
296-
$returnType = new ErrorType();
297+
$nativeObjectType = $nativeType->getObjectTypeOrClassStringObjectType();
298+
$returnType = $nativeObjectType->isObject()->yes() && $nativeObjectType->getObjectClassNames() === []
299+
? new MixedType()
300+
: new ErrorType();
297301
} else {
298302
$returnType = ParametersAcceptorSelector::combineAcceptors($methodReflection->getVariants())->getNativeReturnType();
299303
}
300304

301305
return NullsafeShortCircuitingHelper::getType($scope, $expr->var, $returnType);
302306
}
303307

308+
$calledOnType = $scope->getType($expr->var);
304309
$returnType = $this->methodCallReturnTypeHelper->methodCallReturnType(
305310
$scope,
306-
$scope->getType($expr->var),
311+
$calledOnType,
307312
$expr->name->name,
308313
$expr,
309314
);
310315
if ($returnType === null) {
311-
$returnType = new ErrorType();
316+
$objectType = $calledOnType->getObjectTypeOrClassStringObjectType();
317+
$returnType = $objectType->isObject()->yes() && $objectType->getObjectClassNames() === []
318+
? new MixedType()
319+
: new ErrorType();
312320
}
313321
return NullsafeShortCircuitingHelper::getType($scope, $expr->var, $returnType);
314322
}

0 commit comments

Comments
 (0)