Skip to content

Commit 855a825

Browse files
phpstan-botclaude
andcommitted
Revert class-string static call to ErrorType per review
Keep ErrorType for `$class::foo()` on non-generic class-string, consistent with how `object::foo()` reports an error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1bf4599 commit 855a825

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

src/Analyser/ExprHandler/StaticCallHandler.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -291,28 +291,20 @@ public function resolveType(MutatingScope $scope, Expr $expr): Type
291291
return $callType;
292292
}
293293

294-
$calledOnClassString = false;
295294
if ($expr->class instanceof Name) {
296295
$staticMethodCalledOnType = $this->resolveTypeByNameWithLateStaticBinding($scope, $expr->class, $expr->name);
297296
} else {
298-
$classType = TypeCombinator::removeNull($scope->getType($expr->class));
299-
$calledOnClassString = $classType->isClassString()->yes();
300-
$staticMethodCalledOnType = $classType->getObjectTypeOrClassStringObjectType();
297+
$staticMethodCalledOnType = TypeCombinator::removeNull($scope->getType($expr->class))->getObjectTypeOrClassStringObjectType();
301298
}
302299

303-
$methodName = $expr->name->toString();
304300
$callType = $this->methodCallReturnTypeHelper->methodCallReturnType(
305301
$scope,
306302
$staticMethodCalledOnType,
307-
$methodName,
303+
$expr->name->toString(),
308304
$expr,
309305
);
310306
if ($callType === null) {
311-
if ($calledOnClassString && $staticMethodCalledOnType->hasMethod($methodName)->maybe()) {
312-
$callType = new MixedType();
313-
} else {
314-
$callType = new ErrorType();
315-
}
307+
$callType = new ErrorType();
316308
}
317309

318310
if ($expr->class instanceof Expr) {

tests/PHPStan/Analyser/nsrt/bug-9844.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ class HelloWorld
1212
*/
1313
public function sayHello(string $class): void
1414
{
15-
assertType('mixed', $class::foo());
15+
assertType('*ERROR*', $class::foo());
1616
}
1717
}

0 commit comments

Comments
 (0)