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

Expand object-with-properties

Fixes #4057
This commit is contained in:
Brown 2020-08-25 10:15:56 -04:00
parent 7dba9bc50a
commit 3f50fbc116
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 if ($return_type instanceof Type\Atomic\TCallable
|| $return_type instanceof Type\Atomic\TFn || $return_type instanceof Type\Atomic\TFn
) { ) {

View File

@ -315,7 +315,27 @@ class TypeAnnotationTest extends TestCase
echo $elt["p1"]; 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;
}
}'
],
]; ];
} }