@@ -96,20 +96,25 @@ public function hasSilentVoid(FunctionLike $functionLike) : bool
9696 */
9797 private function hasStmtsAlwaysReturnOrExit (array $ stmts ) : bool
9898 {
99- // early label check
99+ // early label check position key stmt
100100 // as label can be defined later after goto
101+ $ hasAlwaysReturnOrExitAfterLabelPosition = null ;
101102 foreach ($ stmts as $ key => $ stmt ) {
102- if ($ stmt instanceof Label && isset ($ stmts [$ key + 1 ])) {
103- return $ this ->hasStmtsAlwaysReturnOrExit (\array_slice ($ stmts , $ key + 1 ));
103+ if ($ stmt instanceof Label && isset ($ stmts [$ key + 1 ]) && $ this ->hasStmtsAlwaysReturnOrExit (\array_slice ($ stmts , $ key + 1 ))) {
104+ $ hasAlwaysReturnOrExitAfterLabelPosition = $ key ;
105+ break ;
104106 }
105107 }
106- foreach ($ stmts as $ stmt ) {
108+ foreach ($ stmts as $ key => $ stmt ) {
107109 if ($ this ->neverFuncCallAnalyzer ->isWithNeverTypeExpr ($ stmt )) {
108110 return \true;
109111 }
110112 if ($ this ->isStopped ($ stmt )) {
111113 return \true;
112114 }
115+ if ($ stmt instanceof Goto_ && $ hasAlwaysReturnOrExitAfterLabelPosition < $ key ) {
116+ return \true;
117+ }
113118 // has switch with always return
114119 if ($ stmt instanceof Switch_ && $ this ->isSwitchWithAlwaysReturnOrExit ($ stmt )) {
115120 return \true;
@@ -183,7 +188,7 @@ private function isStopped(Stmt $stmt) : bool
183188 if ($ stmt instanceof Expression) {
184189 $ stmt = $ stmt ->expr ;
185190 }
186- return $ stmt instanceof Throw_ || $ stmt instanceof Exit_ || $ stmt instanceof Return_ && $ stmt ->expr instanceof Expr || $ stmt instanceof Yield_ || $ stmt instanceof YieldFrom || $ stmt instanceof Goto_ ;
191+ return $ stmt instanceof Throw_ || $ stmt instanceof Exit_ || $ stmt instanceof Return_ && $ stmt ->expr instanceof Expr || $ stmt instanceof Yield_ || $ stmt instanceof YieldFrom;
187192 }
188193 private function isSwitchWithAlwaysReturnOrExit (Switch_ $ switch ) : bool
189194 {
0 commit comments