diff --git a/src/Psalm/Internal/Type/TypeParser.php b/src/Psalm/Internal/Type/TypeParser.php index df330c89b..443b18505 100644 --- a/src/Psalm/Internal/Type/TypeParser.php +++ b/src/Psalm/Internal/Type/TypeParser.php @@ -718,10 +718,6 @@ class TypeParser continue; } - if ($type instanceof TCallable) { - $type = new TCallableObject($from_docblock, $type); - } - if ($type instanceof TCallableObject) { $types[] = new TUnknownClassString($type, false, $from_docblock); continue; diff --git a/tests/IntersectionTypeTest.php b/tests/IntersectionTypeTest.php index 655818067..acf90438c 100644 --- a/tests/IntersectionTypeTest.php +++ b/tests/IntersectionTypeTest.php @@ -92,29 +92,6 @@ final class IntersectionTypeTest extends TestCase 'assertions' => [], 'ignored_issues' => ['UnsafeInstantiation', 'MixedMethodCall'], ], - 'classStringOfCallableWillBeTreatedAsCallableObject' => [ - 'code' => ' $className - */ - function takesCallableObject(string $className): int { - $object = new $className(); - return $object(); - } - - class Foo - { - public function __invoke(): int - { - return 0; - } - } - - takesCallableObject(Foo::class); - ', - 'assertions' => [], - 'ignored_issues' => ['UnsafeInstantiation', 'MixedMethodCall'], - ], 'classStringOfCallableObjectEqualsObjectWithCallableIntersection' => [ 'code' => ' 'MixedMethodCall', ], + 'classStringOfCallableIsNotAllowed' => [ + # Ref: https://github.com/phpstan/phpstan/issues/9148 + 'code' => ' $className + */ + function takesCallableObject(string $className): int { + $object = new $className(); + return $object(); + } + + class Foo + { + public function __invoke(): int + { + return 0; + } + } + + takesCallableObject(Foo::class); + ', + 'error_message' => 'class-string param can only target', + 'error_levels' => ['UnsafeInstantiation', 'MixedMethodCall'], + ], ]; } }