1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Expand object-with-properties

Fixes #4057
This commit is contained in:
Brown 2020-08-25 10:15:56 -04:00 committed by Daniil Gentili
parent f9b48163e0
commit 8ca604a533
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 36 additions and 1 deletions

View File

@ -414,6 +414,21 @@ class TypeExpander
);
}
if ($return_type instanceof Type\Atomic\TObjectWithProperties) {
foreach ($return_type->properties as &$property_type) {
$property_type = self::expandUnion(
$codebase,
$property_type,
$self_class,
$static_class_type,
$parent_class,
$evaluate_class_constants,
$evaluate_conditional_types,
$final
);
}
}
if ($return_type instanceof Type\Atomic\TCallable
|| $return_type instanceof Type\Atomic\TFn
) {

View File

@ -315,7 +315,27 @@ class TypeAnnotationTest extends TestCase
echo $elt["p1"];
}
}'
]
],
'objectWithPropertiesAlias' => [
'<?php
/**
* @psalm-type FooStruct=string
*/
class A {}
/**
* @psalm-import-type FooStruct from A as F2
*/
class B {
/**
* @param object{foo: F2} $a
* @return object{foo: string}
*/
public function bar($a) {
return $a;
}
}'
],
];
}