diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 5d87f9c98e..164a9eec03 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -4641,7 +4641,7 @@ private function getTypeToInstantiateForNew(Type $type): Type foreach ($type->getTypes() as $innerType) { $decidedType = $decideType($innerType); if ($decidedType === null) { - return new MixedType(); + return new ObjectWithoutClassType(); } $types[] = $decidedType; @@ -4652,7 +4652,7 @@ private function getTypeToInstantiateForNew(Type $type): Type $decidedType = $decideType($type); if ($decidedType === null) { - return new MixedType(); + return new ObjectWithoutClassType(); } return $decidedType; diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index 4a1f5a3082..d168c48d44 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -1712,7 +1712,7 @@ public function dataDeductedTypes(): array '$loremObjectLiteral', ], [ - 'mixed', + 'object', '$mixedObjectLiteral', ], [ @@ -10897,6 +10897,11 @@ public function dataBug4577(): array return $this->gatherAssertTypes(__DIR__ . '/data/bug-4577.php'); } + public function dataBug4579(): array + { + return $this->gatherAssertTypes(__DIR__ . '/data/bug-4579.php'); + } + /** * @param string $file * @return array @@ -11138,6 +11143,7 @@ private function gatherAssertTypes(string $file): array * @dataProvider dataArrayMapClosure * @dataProvider dataBug4573 * @dataProvider dataBug4577 + * @dataProvider dataBug4579 * @param string $assertType * @param string $file * @param mixed ...$args diff --git a/tests/PHPStan/Analyser/data/bug-4579.php b/tests/PHPStan/Analyser/data/bug-4579.php new file mode 100644 index 0000000000..5894995591 --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-4579.php @@ -0,0 +1,12 @@ +|DateTimeInterface', $a); @@ -36,7 +36,7 @@ function testMixed($a) { * @param object $a */ function testObject($a) { - assertType('mixed', new $a()); + assertType('object', new $a()); if (is_subclass_of($a, 'DateTimeInterface')) { assertType('DateTimeInterface', $a); @@ -47,7 +47,7 @@ function testObject($a) { * @param string $a */ function testString($a) { - assertType('mixed', new $a()); + assertType('object', new $a()); if (is_subclass_of($a, 'DateTimeInterface')) { assertType('class-string', $a); @@ -63,7 +63,7 @@ function testString($a) { * @param string|object $a */ function testStringObject($a) { - assertType('mixed', new $a()); + assertType('object', new $a()); if (is_subclass_of($a, 'DateTimeInterface')) { assertType('class-string|DateTimeInterface', $a); @@ -92,6 +92,7 @@ function testClassExists(string $str) assertType('string', $str); if (class_exists($str)) { assertType('class-string', $str); + assertType('object', new $str()); } $existentClass = \stdClass::class;