From 1aef99d3c0bf5edb7448622f45376923c7e4aa3c Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Fri, 21 Jan 2022 09:05:28 +0100 Subject: [PATCH] Regression test Closes https://github.com/phpstan/phpstan/issues/4357 --- .../Analyser/NodeScopeResolverTest.php | 1 + tests/PHPStan/Analyser/data/bug-4357.php | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/PHPStan/Analyser/data/bug-4357.php diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index 794b3535b1..70aac8b22f 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -618,6 +618,7 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6404.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6399.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4357.php'); } /** diff --git a/tests/PHPStan/Analyser/data/bug-4357.php b/tests/PHPStan/Analyser/data/bug-4357.php new file mode 100644 index 0000000000..d8e36019c8 --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-4357.php @@ -0,0 +1,26 @@ + */ + private $arr = null; + + public function test(): void { + if ($this->arr === null) { + return; + } + + assertType('array', $this->arr); + + unset($this->arr['hello']); + + assertType('array', $this->arr); + + if (count($this->arr) === 0) { + $this->arr = null; + } + } +}