File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
tests/PHPStan/Rules/Comparison/data Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 1313use PHPStan \Rules \Rule ;
1414use PHPStan \Rules \RuleErrorBuilder ;
1515use PHPStan \Type \Constant \ConstantBooleanType ;
16+ use PHPStan \Type \NeverType ;
1617
1718/**
1819 * @implements Rule<BreaklessWhileLoopNode>
@@ -67,6 +68,12 @@ public function processNode(
6768 $ originalNode = $ node ->getOriginalNode ();
6869 $ exprType = $ this ->helper ->getBooleanType ($ scope , $ originalNode ->cond );
6970 if ($ exprType ->isTrue ()->yes ()) {
71+ $ ref = $ scope ->getFunction () ?? $ scope ->getAnonymousFunctionReflection ();
72+
73+ if ($ ref !== null && $ ref ->getReturnType () instanceof NeverType) {
74+ return [];
75+ }
76+
7077 $ addTip = function (RuleErrorBuilder $ ruleErrorBuilder ) use ($ scope , $ originalNode ): RuleErrorBuilder {
7178 if (!$ this ->treatPhpDocTypesAsCertain ) {
7279 return $ ruleErrorBuilder ;
Original file line number Diff line number Diff line change @@ -91,4 +91,18 @@ public function doBar8(array $a): void
9191 }
9292 }
9393
94+ public function doBar9 () :never
95+ {
96+ while (true ) {
97+ // do stuff
98+ }
99+ }
100+
101+ }
102+
103+ function doFoo () : never
104+ {
105+ while (true ) {
106+ // do stuff
107+ }
94108}
You can’t perform that action at this time.
0 commit comments