Repository: phpactor/phpactor (php)

Issue:
`new class-string<Foo>()` results in `class-string` not a class
![image](https://user-images.githubusercontent.com/530801/213912705-d08a20bc-6cad-4b58-9c5b-7a3f0c0ecda7.png)


Pull request description:
gh-2056: Support new class-string
Fixes #2056 

Patch:
diff --git a/lib/WorseReflection/Core/Inference/Resolver/ObjectCreationExpressionResolver.php b/lib/WorseReflection/Core/Inference/Resolver/ObjectCreationExpressionResolver.php
index a48986c6..8a998be5 100644
--- a/lib/WorseReflection/Core/Inference/Resolver/ObjectCreationExpressionResolver.php
+++ b/lib/WorseReflection/Core/Inference/Resolver/ObjectCreationExpressionResolver.php
@@ -13,6 +13,8 @@ use Phpactor\WorseReflection\Core\Inference\NodeContext;
 use Phpactor\WorseReflection\Core\Inference\Resolver;
 use Phpactor\WorseReflection\Core\Inference\NodeContextResolver;
 use Phpactor\WorseReflection\Core\Type;
+use Phpactor\WorseReflection\Core\TypeFactory;
+use Phpactor\WorseReflection\Core\Type\ClassStringType;
 use Phpactor\WorseReflection\Core\Type\ClassType;
 use Phpactor\WorseReflection\Core\Type\GenericClassType;
 
@@ -33,6 +35,13 @@ class ObjectCreationExpressionResolver implements Resolver
         $classContext = $resolver->resolveNode($frame, $node->classTypeDesignator);
         $classType = $classContext->type();
 
+        if ($classType instanceof ClassStringType) {
+            if ($classType->className() === null) {
+                return $classContext->withType(TypeFactory::object());
+            }
+            $classType = TypeFactory::class($classType->className());
+        }
+
         if ($classType instanceof ClassType) {
             return $classContext->withType($this->resolveClassType($resolver, $frame, $node, $classType));
         }


Test patch:
diff --git a/lib/WorseReflection/Tests/Inference/type/class-string-new-no-type.test b/lib/WorseReflection/Tests/Inference/type/class-string-new-no-type.test
new file mode 100644
index 00000000..5d12778b
--- /dev/null
+++ b/lib/WorseReflection/Tests/Inference/type/class-string-new-no-type.test
@@ -0,0 +1,6 @@
+<?php
+
+/** @var class-string $f */
+$obj = new $f;
+
+wrAssertType('object', $obj);
diff --git a/lib/WorseReflection/Tests/Inference/type/class-string-new.test b/lib/WorseReflection/Tests/Inference/type/class-string-new.test
new file mode 100644
index 00000000..b3c93093
--- /dev/null
+++ b/lib/WorseReflection/Tests/Inference/type/class-string-new.test
@@ -0,0 +1,6 @@
+<?php
+
+$f = Foo::class;
+$f = new $f;
+
+wrAssertType('Foo', $f);