diff --git a/src/Psalm/Type/Reconciler.php b/src/Psalm/Type/Reconciler.php index b520ab9d52f..0daddae5659 100644 --- a/src/Psalm/Type/Reconciler.php +++ b/src/Psalm/Type/Reconciler.php @@ -54,6 +54,7 @@ use Psalm\Type\Atomic\TNever; use Psalm\Type\Atomic\TNull; use Psalm\Type\Atomic\TObject; +use Psalm\Type\Atomic\TObjectWithProperties; use Psalm\Type\Atomic\TString; use Psalm\Type\Atomic\TTemplateParam; use ReflectionProperty; @@ -845,6 +846,9 @@ private static function getValueForKey( if ($existing_key_type_part instanceof TNull) { $class_property_type = Type::getNull(); + } elseif ($existing_key_type_part instanceof TObjectWithProperties) { + $class_property_type = + $existing_key_type_part->properties[$property_name] ?? Type::getMixed(); } elseif ($existing_key_type_part instanceof TMixed || $existing_key_type_part instanceof TObject || ($existing_key_type_part instanceof TNamedObject diff --git a/tests/ReturnTypeProvider/GetObjectVarsTest.php b/tests/ReturnTypeProvider/GetObjectVarsTest.php index 814b9decb91..283e49cca5b 100644 --- a/tests/ReturnTypeProvider/GetObjectVarsTest.php +++ b/tests/ReturnTypeProvider/GetObjectVarsTest.php @@ -24,6 +24,19 @@ final class C { 'assertions' => ['$ret' => 'array{prop: string}'], ]; + yield 'retrurnsNotMixed' => [ + 'code' => 'g && $b) { + return $o->g; + } + return true; + }', + ]; + yield 'returnsSealedArrayForFinalClass' => [ 'code' => '