From bd8df0e820cbad0adbd89300cc257b20ee799b32 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Wed, 13 Jan 2021 11:35:44 -0500 Subject: [PATCH] Fix #5001 - update variables after context after type change from empty Empty is the invalid state, and some old logic here was causing a bug --- src/Psalm/Context.php | 5 +---- tests/Loop/WhileTest.php | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/Psalm/Context.php b/src/Psalm/Context.php index de698bc26..f62616160 100644 --- a/src/Psalm/Context.php +++ b/src/Psalm/Context.php @@ -463,10 +463,7 @@ class Context $new_type = $new_vars_in_scope[$var_id]; - if (!$this_type->isEmpty() - && !$new_type->isEmpty() - && !$this_type->equals($new_type) - ) { + if (!$this_type->equals($new_type)) { $redefined_vars[$var_id] = $this_type; } } diff --git a/tests/Loop/WhileTest.php b/tests/Loop/WhileTest.php index e62686f64..5629a4a21 100644 --- a/tests/Loop/WhileTest.php +++ b/tests/Loop/WhileTest.php @@ -585,6 +585,44 @@ class WhileTest extends \Psalm\Tests\TestCase } }' ], + 'ifNestedInsideLoop' => [ + ' [ + '