Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down
25 changes: 25 additions & 0 deletions tests/PHPStan/Analyser/data/bug-7913.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types = 1);

namespace Bug7913b;

use function PHPStan\Testing\assertType;

const X = [];
assertType('array{}', X);
if (!empty(X)) {
assertType('*NEVER*', X);
foreach (X as $y) {
print($y);
}
}
assertType('array{}', X);

$x = [];
assertType('array{}', $x);
if (!empty($x)) {
assertType('*NEVER*', $x);
foreach ($x as $y) {
print($y);
}
}
assertType('array{}', $x);
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Arrays/DeadForeachRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public function testRule(): void
]);
}

public function testBug7913(): void
{
$this->analyse([__DIR__ . '/data/bug-7913.php'], []);
}

}
17 changes: 17 additions & 0 deletions tests/PHPStan/Rules/Arrays/data/bug-7913.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types = 1);

namespace Bug7913;

const X = [];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried wrapping it in a method/function, but using const like in the repro example, only works in top level code, it seems

if (!empty(X)) {
foreach (X as $y) {
print($y);
}
}

$x = [];
if (!empty($x)) {
foreach ($x as $y) {
print($y);
}
}