From 3e100b15d9e93a87548fde4b7218ccad6fc0a622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20B=C3=B6sing?= <2189546+boesing@users.noreply.github.com> Date: Fri, 15 Sep 2023 20:19:54 +0200 Subject: [PATCH] bugfix: allow object assertions for mixed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com> --- .../Internal/Type/SimpleAssertionReconciler.php | 2 +- tests/AssertAnnotationTest.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php index d08e61561ee..5e0d0a827ed 100644 --- a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php @@ -1600,7 +1600,7 @@ private static function reconcileObject( bool $is_equality ): Union { if ($existing_var_type->hasMixed()) { - return Type::getObject(); + return new Union([$assertion_type]); } $old_var_type_string = $existing_var_type->getId(); diff --git a/tests/AssertAnnotationTest.php b/tests/AssertAnnotationTest.php index 7bba9297f2c..18016a3ca5c 100644 --- a/tests/AssertAnnotationTest.php +++ b/tests/AssertAnnotationTest.php @@ -2967,6 +2967,22 @@ final class Qoo extends AbstractSingleInstancePluginManager 'ignored_issues' => [], 'php_version' => '8.1', ], + 'objectShapeAssertion' => [ + 'code' => ' [ + '$value===' => 'object{foo:string, bar:int}', + ], + 'ignored_issues' => [], + 'php_version' => '8.0', + ], ]; }