From 3f50fbc116b45330d33f092359c23428d3273f64 Mon Sep 17 00:00:00 2001 From: Brown Date: Tue, 25 Aug 2020 10:15:56 -0400 Subject: [PATCH] Expand object-with-properties Fixes #4057 --- src/Psalm/Internal/Type/TypeExpander.php | 15 +++++++++++++++ tests/TypeAnnotationTest.php | 22 +++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Type/TypeExpander.php b/src/Psalm/Internal/Type/TypeExpander.php index 12fd1194f..bdbe90616 100644 --- a/src/Psalm/Internal/Type/TypeExpander.php +++ b/src/Psalm/Internal/Type/TypeExpander.php @@ -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 ) { diff --git a/tests/TypeAnnotationTest.php b/tests/TypeAnnotationTest.php index 85d0fad4f..3551674a3 100644 --- a/tests/TypeAnnotationTest.php +++ b/tests/TypeAnnotationTest.php @@ -315,7 +315,27 @@ class TypeAnnotationTest extends TestCase echo $elt["p1"]; } }' - ] + ], + 'objectWithPropertiesAlias' => [ + '