Skip to content

Commit 0c9abf7

Browse files
committed
added regression test
1 parent 1e0bddd commit 0c9abf7

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeMethodCallRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@ public function testBug13566(): void
296296
$this->analyse([__DIR__ . '/data/bug-13566.php'], []);
297297
}
298298

299+
public function testBug10337(): void
300+
{
301+
$this->treatPhpDocTypesAsCertain = true;
302+
$this->analyse([__DIR__ . '/data/bug-10337.php'], []);
303+
}
304+
299305
public static function getAdditionalConfigFiles(): array
300306
{
301307
return [
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Bug10337;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class App
8+
{
9+
/**
10+
* @return ($calledFromShutdownHandler is true ? void : never)
11+
*/
12+
public function callExit(bool $calledFromShutdownHandler = false): void
13+
{
14+
// run before shutdown code here
15+
16+
if (!$calledFromShutdownHandler) {
17+
exit;
18+
}
19+
}
20+
21+
public function testOnlyVoid(): void
22+
{
23+
(new App())->callExit(true);
24+
}
25+
26+
/**
27+
* @return never
28+
*/
29+
public function testVoidAndNever(): void
30+
{
31+
$app = new App();
32+
assertType('null', $app->callExit(true));
33+
assertType('never', $app->callExit(false));
34+
}
35+
36+
/**
37+
* @return never
38+
*/
39+
public function testVoidAndNever2(): void
40+
{
41+
$app = new class() extends App {
42+
};
43+
assertType('null', $app->callExit(true));
44+
assertType('never', $app->callExit(false));
45+
}
46+
47+
/**
48+
* @return never
49+
*/
50+
public function testVoidAndNever3(): void
51+
{
52+
$app = new class() extends App {
53+
#[\Override]
54+
public function callExit(bool $calledFromShutdownHandler = false): void
55+
{
56+
parent::callExit($calledFromShutdownHandler);
57+
}
58+
};
59+
assertType('null', $app->callExit(true));
60+
assertType('never', $app->callExit(false));
61+
}
62+
}

0 commit comments

Comments
 (0)