diff --git a/src/Psalm/Type/Atomic.php b/src/Psalm/Type/Atomic.php index 42964c9e5..06199da2e 100644 --- a/src/Psalm/Type/Atomic.php +++ b/src/Psalm/Type/Atomic.php @@ -224,7 +224,11 @@ abstract class Atomic implements TypeNode return $php_version !== null ? new TNamedObject($value) : new TNull(); case 'mixed': - return $php_version !== null ? new TNamedObject($value) : new TMixed(); + if ($php_version === null || $php_version[0] >= 8) { + return new TMixed(); + } + + return new TNamedObject($value); case 'callable-object': return new TCallableObject(); diff --git a/tests/ReturnTypeTest.php b/tests/ReturnTypeTest.php index b11db46df..65aadc2c0 100644 --- a/tests/ReturnTypeTest.php +++ b/tests/ReturnTypeTest.php @@ -865,6 +865,8 @@ class ReturnTypeTest extends TestCase ], 'returnStaticThis' => [ 'getThis()->foo();', ], + 'returnMixed' => [ + '