From 9d8528b071411f2d841fed5349705de141883dfe Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 1 Nov 2022 08:44:42 +0100 Subject: [PATCH 1/3] added regression test --- .../Rules/Arrays/DeadForeachRuleTest.php | 5 +++++ tests/PHPStan/Rules/Arrays/data/bug-7913.php | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/PHPStan/Rules/Arrays/data/bug-7913.php diff --git a/tests/PHPStan/Rules/Arrays/DeadForeachRuleTest.php b/tests/PHPStan/Rules/Arrays/DeadForeachRuleTest.php index a5703438228..f4cf678a4d2 100644 --- a/tests/PHPStan/Rules/Arrays/DeadForeachRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/DeadForeachRuleTest.php @@ -30,4 +30,9 @@ public function testRule(): void ]); } + public function testBug7913(): void + { + $this->analyse([__DIR__ . '/data/bug-7913.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Arrays/data/bug-7913.php b/tests/PHPStan/Rules/Arrays/data/bug-7913.php new file mode 100644 index 00000000000..1bd3465b0bc --- /dev/null +++ b/tests/PHPStan/Rules/Arrays/data/bug-7913.php @@ -0,0 +1,17 @@ + Date: Tue, 1 Nov 2022 08:59:42 +0100 Subject: [PATCH 2/3] added NodeScopeResolverTest --- .../Analyser/NodeScopeResolverTest.php | 2 +- tests/PHPStan/Analyser/data/bug-7913.php | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/PHPStan/Analyser/data/bug-7913.php diff --git a/tests/PHPStan/Analyser/NodeScopeResolverTest.php b/tests/PHPStan/Analyser/NodeScopeResolverTest.php index 4d382775455..caf6b47887c 100644 --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php @@ -1116,8 +1116,8 @@ public function dataFileAsserts(): iterable yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8225.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8242.php'); yield from $this->gatherAssertTypes(__DIR__ . '/data/composer-treatPhpDocTypesAsCertainBug.php'); - yield from $this->gatherAssertTypes(__DIR__ . '/data/closure-retain-expression-types.php'); + yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7913.php'); } /** diff --git a/tests/PHPStan/Analyser/data/bug-7913.php b/tests/PHPStan/Analyser/data/bug-7913.php new file mode 100644 index 00000000000..b902affcca2 --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-7913.php @@ -0,0 +1,22 @@ + Date: Tue, 1 Nov 2022 09:00:47 +0100 Subject: [PATCH 3/3] also assert on variables --- tests/PHPStan/Analyser/data/bug-7913.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/PHPStan/Analyser/data/bug-7913.php b/tests/PHPStan/Analyser/data/bug-7913.php index b902affcca2..7afd5511db1 100644 --- a/tests/PHPStan/Analyser/data/bug-7913.php +++ b/tests/PHPStan/Analyser/data/bug-7913.php @@ -15,8 +15,11 @@ assertType('array{}', X); $x = []; +assertType('array{}', $x); if (!empty($x)) { + assertType('*NEVER*', $x); foreach ($x as $y) { print($y); } } +assertType('array{}', $x);