Skip to content

Commit 2327cc0

Browse files
committed
Added regression test
1 parent 54cf6eb commit 2327cc0

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,4 +1232,18 @@ public function testBug1O580(): void
12321232
]);
12331233
}
12341234

1235+
public function testBug4443(): void
1236+
{
1237+
if (PHP_VERSION_ID < 80000) {
1238+
$this->markTestSkipped('Test requires PHP 8.0.');
1239+
}
1240+
1241+
$this->analyse([__DIR__ . '/data/bug-4443.php'], [
1242+
[
1243+
'Method Bug4443\HelloWorld::getArray() should return array<mixed> but returns array<mixed>|null.',
1244+
22
1245+
]
1246+
]);
1247+
}
1248+
12351249
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Bug4443;
4+
5+
class HelloWorld
6+
{
7+
/** @var array<mixed> */
8+
private static ?array $arr = null;
9+
10+
private static function setup(): void
11+
{
12+
self::$arr = null;
13+
}
14+
15+
/** @return array<mixed> */
16+
public static function getArray(): array
17+
{
18+
if (self::$arr === null) {
19+
self::$arr = [];
20+
self::setup();
21+
}
22+
return self::$arr;
23+
}
24+
}
25+
26+
HelloWorld::getArray();

0 commit comments

Comments
 (0)