Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object property types #11291

Merged
merged 2 commits into from
Feb 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Psalm/Type/Reconciler.php
Original file line number Diff line number Diff line change
@@ -55,6 +55,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;
@@ -846,6 +847,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
13 changes: 13 additions & 0 deletions tests/ReturnTypeProvider/GetObjectVarsTest.php
Original file line number Diff line number Diff line change
@@ -26,6 +26,19 @@ final class C {
'assertions' => ['$ret' => 'array{prop: string}'],
];

yield 'retrurnsNotMixed' => [
'code' => '<?php
/**
* @param object{g: bool} $o
*/
function f(object $o, bool $b): bool {
if ($o->g && $b) {
return $o->g;
}
return true;
}',
];

yield 'returnsSealedArrayForFinalClass' => [
'code' => '<?php
final class C {
Loading