Skip to content

Commit cabf58f

Browse files
phpstan-botclaude
authored andcommitted
Add non-regression test for bug 5271
Closes phpstan/phpstan#5271 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c253832 commit cabf58f

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php // lint >= 8.0
2+
3+
declare(strict_types = 1);
4+
5+
namespace Bug5271;
6+
7+
use function PHPStan\Testing\assertNativeType;
8+
use function PHPStan\Testing\assertType;
9+
10+
class BannerPatternLayer
11+
{
12+
13+
}
14+
15+
class Banner
16+
{
17+
18+
/** @var list<BannerPatternLayer> */
19+
private array $patterns = [];
20+
21+
public function test(): void
22+
{
23+
$this->patterns = array_filter($this->patterns, fn($v) => $v instanceof BannerPatternLayer);
24+
}
25+
26+
public function testClosure(): void
27+
{
28+
$this->patterns = array_filter($this->patterns, function ($v) {
29+
assertType('Bug5271\BannerPatternLayer', $v);
30+
assertNativeType('mixed', $v);
31+
return $v instanceof BannerPatternLayer;
32+
});
33+
}
34+
35+
public function testArrow(): void
36+
{
37+
array_filter($this->patterns, fn($v) => assertNativeType('mixed', $v));
38+
}
39+
40+
}

tests/PHPStan/Rules/Classes/ImpossibleInstanceOfRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,4 +599,10 @@ public function testBug13975(string $file): void
599599
$this->analyse([$file], []);
600600
}
601601

602+
public function testBug5271(): void
603+
{
604+
$this->treatPhpDocTypesAsCertain = false;
605+
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-5271.php'], []);
606+
}
607+
602608
}

0 commit comments

Comments
 (0)