@@ -261,7 +261,7 @@ public function processNodes(
261
261
}
262
262
263
263
/**
264
- * @param \PhpParser\Node $parentNode
264
+ * @param \PhpParser\Node\Stmt|\PhpParser\Node\Expr $parentNode
265
265
* @param \PhpParser\Node\Stmt[] $stmts
266
266
* @param \PHPStan\Analyser\MutatingScope $scope
267
267
* @param callable(\PhpParser\Node $node, Scope $scope): void $nodeCallback
@@ -298,6 +298,7 @@ public function processStmtNodes(
298
298
$ nodeCallback (new ExecutionEndNode (
299
299
$ stmt ,
300
300
new StatementResult (
301
+ $ stmt ,
301
302
$ scope ,
302
303
$ hasYield ,
303
304
$ statementResult ->isAlwaysTerminating (),
@@ -323,7 +324,7 @@ public function processStmtNodes(
323
324
break ;
324
325
}
325
326
326
- $ statementResult = new StatementResult ($ scope , $ hasYield , $ alreadyTerminated , $ exitPoints , $ throwPoints );
327
+ $ statementResult = new StatementResult ($ parentNode instanceof Node \Stmt ? $ parentNode : new Node \ Stmt \ Expression ( $ parentNode ), $ scope , $ hasYield , $ alreadyTerminated , $ exitPoints , $ throwPoints );
327
328
if ($ stmtCount === 0 && $ shouldCheckLastStatement ) {
328
329
/** @var Node\Stmt\Function_|Node\Stmt\ClassMethod|Expr\Closure $parentNode */
329
330
$ parentNode = $ parentNode ;
@@ -372,12 +373,12 @@ private function processStmtNode(
372
373
) {
373
374
$ methodReflection = $ scope ->getClassReflection ()->getNativeMethod ($ stmt ->name ->toString ());
374
375
if ($ methodReflection instanceof NativeMethodReflection) {
375
- return new StatementResult ($ scope , false , false , [], []);
376
+ return new StatementResult ($ stmt , $ scope , false , false , [], []);
376
377
}
377
378
if ($ methodReflection instanceof PhpMethodReflection) {
378
379
$ declaringTrait = $ methodReflection ->getDeclaringTrait ();
379
380
if ($ declaringTrait === null || $ declaringTrait ->getName () !== $ scope ->getTraitReflection ()->getName ()) {
380
- return new StatementResult ($ scope , false , false , [], []);
381
+ return new StatementResult ($ stmt , $ scope , false , false , [], []);
381
382
}
382
383
}
383
384
}
@@ -560,7 +561,7 @@ private function processStmtNode(
560
561
$ throwPoints = [];
561
562
}
562
563
563
- return new StatementResult ($ scope , $ hasYield , true , [
564
+ return new StatementResult ($ stmt , $ scope , $ hasYield , true , [
564
565
new StatementExitPoint ($ stmt , $ scope ),
565
566
], $ throwPoints );
566
567
} elseif ($ stmt instanceof Continue_ || $ stmt instanceof Break_) {
@@ -574,7 +575,7 @@ private function processStmtNode(
574
575
$ throwPoints = [];
575
576
}
576
577
577
- return new StatementResult ($ scope , $ hasYield , true , [
578
+ return new StatementResult ($ stmt , $ scope , $ hasYield , true , [
578
579
new StatementExitPoint ($ stmt , $ scope ),
579
580
], $ throwPoints );
580
581
} elseif ($ stmt instanceof Node \Stmt \Expression) {
@@ -589,11 +590,11 @@ private function processStmtNode(
589
590
$ hasYield = $ result ->hasYield ();
590
591
$ throwPoints = $ result ->getThrowPoints ();
591
592
if ($ earlyTerminationExpr !== null ) {
592
- return new StatementResult ($ scope , $ hasYield , true , [
593
+ return new StatementResult ($ stmt , $ scope , $ hasYield , true , [
593
594
new StatementExitPoint ($ stmt , $ scope ),
594
595
], $ throwPoints );
595
596
}
596
- return new StatementResult ($ scope , $ hasYield , false , [], $ throwPoints );
597
+ return new StatementResult ($ stmt , $ scope , $ hasYield , false , [], $ throwPoints );
597
598
} elseif ($ stmt instanceof Node \Stmt \Namespace_) {
598
599
if ($ stmt ->name !== null ) {
599
600
$ scope = $ scope ->enterNamespace ($ stmt ->name ->toString ());
@@ -603,7 +604,7 @@ private function processStmtNode(
603
604
$ hasYield = false ;
604
605
$ throwPoints = [];
605
606
} elseif ($ stmt instanceof Node \Stmt \Trait_) {
606
- return new StatementResult ($ scope , false , false , [], []);
607
+ return new StatementResult ($ stmt , $ scope , false , false , [], []);
607
608
} elseif ($ stmt instanceof Node \Stmt \ClassLike) {
608
609
$ hasYield = false ;
609
610
$ throwPoints = [];
@@ -679,7 +680,7 @@ private function processStmtNode(
679
680
$ result = $ this ->processExprNode ($ stmt ->expr , $ scope , $ nodeCallback , ExpressionContext::createDeep ());
680
681
$ throwPoints = $ result ->getThrowPoints ();
681
682
$ throwPoints [] = ThrowPoint::createExplicit ($ result ->getScope (), $ scope ->getType ($ stmt ->expr ), false );
682
- return new StatementResult ($ result ->getScope (), $ result ->hasYield (), true , [
683
+ return new StatementResult ($ stmt , $ result ->getScope (), $ result ->hasYield (), true , [
683
684
new StatementExitPoint ($ stmt , $ scope ),
684
685
], $ throwPoints );
685
686
} elseif ($ stmt instanceof If_) {
@@ -767,7 +768,7 @@ private function processStmtNode(
767
768
$ finalScope = $ scope ;
768
769
}
769
770
770
- return new StatementResult ($ finalScope , $ hasYield , $ alwaysTerminating , $ exitPoints , $ throwPoints );
771
+ return new StatementResult ($ stmt , $ finalScope , $ hasYield , $ alwaysTerminating , $ exitPoints , $ throwPoints );
771
772
} elseif ($ stmt instanceof Node \Stmt \TraitUse) {
772
773
$ hasYield = false ;
773
774
$ throwPoints = [];
@@ -833,6 +834,7 @@ private function processStmtNode(
833
834
}
834
835
835
836
return new StatementResult (
837
+ $ stmt ,
836
838
$ finalScope ,
837
839
$ finalScopeResult ->hasYield () || $ condResult ->hasYield (),
838
840
$ isIterableAtLeastOnce ->yes () && $ finalScopeResult ->isAlwaysTerminating (),
@@ -906,6 +908,7 @@ private function processStmtNode(
906
908
}
907
909
908
910
return new StatementResult (
911
+ $ stmt ,
909
912
$ finalScope ,
910
913
$ finalScopeResult ->hasYield () || $ condResult ->hasYield (),
911
914
$ isAlwaysTerminating ,
@@ -974,6 +977,7 @@ private function processStmtNode(
974
977
}
975
978
976
979
return new StatementResult (
980
+ $ stmt ,
977
981
$ finalScope ,
978
982
$ bodyScopeResult ->hasYield () || $ hasYield ,
979
983
$ alwaysTerminating ,
@@ -1057,6 +1061,7 @@ private function processStmtNode(
1057
1061
$ finalScope = $ finalScope ->mergeWith ($ scope );
1058
1062
1059
1063
return new StatementResult (
1064
+ $ stmt ,
1060
1065
$ finalScope ,
1061
1066
$ finalScopeResult ->hasYield () || $ hasYield ,
1062
1067
false /* $finalScopeResult->isAlwaysTerminating() && $isAlwaysIterable*/ ,
@@ -1128,7 +1133,7 @@ private function processStmtNode(
1128
1133
$ finalScope = $ scope ->mergeWith ($ finalScope );
1129
1134
}
1130
1135
1131
- return new StatementResult ($ finalScope , $ hasYield , $ alwaysTerminating , $ exitPointsForOuterLoop , $ throwPoints );
1136
+ return new StatementResult ($ stmt , $ finalScope , $ hasYield , $ alwaysTerminating , $ exitPointsForOuterLoop , $ throwPoints );
1132
1137
} elseif ($ stmt instanceof TryCatch) {
1133
1138
$ branchScopeResult = $ this ->processStmtNodes ($ stmt , $ stmt ->stmts , $ scope , $ nodeCallback );
1134
1139
$ branchScope = $ branchScopeResult ->getScope ();
@@ -1298,7 +1303,7 @@ private function processStmtNode(
1298
1303
$ exitPoints = array_merge ($ exitPoints , $ finallyResult ->getExitPoints ());
1299
1304
}
1300
1305
1301
- return new StatementResult ($ finalScope , $ hasYield , $ alwaysTerminating , $ exitPoints , array_merge ($ throwPoints , $ throwPointsForLater ));
1306
+ return new StatementResult ($ stmt , $ finalScope , $ hasYield , $ alwaysTerminating , $ exitPoints , array_merge ($ throwPoints , $ throwPointsForLater ));
1302
1307
} elseif ($ stmt instanceof Unset_) {
1303
1308
$ hasYield = false ;
1304
1309
$ throwPoints = [];
@@ -1393,7 +1398,7 @@ private function processStmtNode(
1393
1398
$ throwPoints = [];
1394
1399
}
1395
1400
1396
- return new StatementResult ($ scope , $ hasYield , false , [], $ throwPoints );
1401
+ return new StatementResult ($ stmt , $ scope , $ hasYield , false , [], $ throwPoints );
1397
1402
}
1398
1403
1399
1404
private function getCurrentClassReflection (Node \Stmt \ClassLike $ stmt , Scope $ scope ): ClassReflection
0 commit comments