@@ -160,8 +160,6 @@ class NodeScopeResolver
160
160
161
161
private bool $ implicitThrows ;
162
162
163
- private bool $ preciseExceptionTracking ;
164
-
165
163
/** @var bool[] filePath(string) => bool(true) */
166
164
private array $ analysedFiles = [];
167
165
@@ -178,7 +176,6 @@ class NodeScopeResolver
178
176
* @param string[][] $earlyTerminatingMethodCalls className(string) => methods(string[])
179
177
* @param array<int, string> $earlyTerminatingFunctionCalls
180
178
* @param bool $implicitThrows
181
- * @param bool $preciseExceptionTracking
182
179
*/
183
180
public function __construct (
184
181
ReflectionProvider $ reflectionProvider ,
@@ -196,8 +193,7 @@ public function __construct(
196
193
bool $ polluteScopeWithAlwaysIterableForeach ,
197
194
array $ earlyTerminatingMethodCalls ,
198
195
array $ earlyTerminatingFunctionCalls ,
199
- bool $ implicitThrows ,
200
- bool $ preciseExceptionTracking
196
+ bool $ implicitThrows
201
197
)
202
198
{
203
199
$ this ->reflectionProvider = $ reflectionProvider ;
@@ -216,7 +212,6 @@ public function __construct(
216
212
$ this ->earlyTerminatingMethodCalls = $ earlyTerminatingMethodCalls ;
217
213
$ this ->earlyTerminatingFunctionCalls = $ earlyTerminatingFunctionCalls ;
218
214
$ this ->implicitThrows = $ implicitThrows ;
219
- $ this ->preciseExceptionTracking = $ preciseExceptionTracking ;
220
215
}
221
216
222
217
/**
@@ -1180,89 +1175,78 @@ private function processStmtNode(
1180
1175
foreach ($ stmt ->catches as $ catchNode ) {
1181
1176
$ nodeCallback ($ catchNode , $ scope );
1182
1177
1183
- if ($ this ->preciseExceptionTracking ) {
1184
- $ catchType = TypeCombinator::union (...array_map (static function (Name $ name ): Type {
1185
- return new ObjectType ($ name ->toString ());
1186
- }, $ catchNode ->types ));
1187
- $ originalCatchType = $ catchType ;
1188
- $ catchType = TypeCombinator::remove ($ catchType , $ pastCatchTypes );
1189
- $ pastCatchTypes = TypeCombinator::union ($ pastCatchTypes , $ originalCatchType );
1190
- $ matchingThrowPoints = [];
1191
- $ newThrowPoints = [];
1192
- foreach ($ throwPoints as $ throwPoint ) {
1193
- if (!$ throwPoint ->isExplicit () && !$ catchType ->isSuperTypeOf (new ObjectType (\Throwable::class))->yes ()) {
1194
- continue ;
1195
- }
1196
- $ isSuperType = $ catchType ->isSuperTypeOf ($ throwPoint ->getType ());
1197
- if ($ isSuperType ->no ()) {
1198
- continue ;
1199
- }
1178
+ $ catchType = TypeCombinator::union (...array_map (static function (Name $ name ): Type {
1179
+ return new ObjectType ($ name ->toString ());
1180
+ }, $ catchNode ->types ));
1181
+ $ originalCatchType = $ catchType ;
1182
+ $ catchType = TypeCombinator::remove ($ catchType , $ pastCatchTypes );
1183
+ $ pastCatchTypes = TypeCombinator::union ($ pastCatchTypes , $ originalCatchType );
1184
+ $ matchingThrowPoints = [];
1185
+ $ newThrowPoints = [];
1186
+ foreach ($ throwPoints as $ throwPoint ) {
1187
+ if (!$ throwPoint ->isExplicit () && !$ catchType ->isSuperTypeOf (new ObjectType (\Throwable::class))->yes ()) {
1188
+ continue ;
1189
+ }
1190
+ $ isSuperType = $ catchType ->isSuperTypeOf ($ throwPoint ->getType ());
1191
+ if ($ isSuperType ->no ()) {
1192
+ continue ;
1193
+ }
1194
+ $ matchingThrowPoints [] = $ throwPoint ;
1195
+ }
1196
+ $ hasExplicit = count ($ matchingThrowPoints ) > 0 ;
1197
+ foreach ($ throwPoints as $ throwPoint ) {
1198
+ $ isSuperType = $ catchType ->isSuperTypeOf ($ throwPoint ->getType ());
1199
+ if (!$ hasExplicit && !$ isSuperType ->no ()) {
1200
1200
$ matchingThrowPoints [] = $ throwPoint ;
1201
1201
}
1202
- $ hasExplicit = count ($ matchingThrowPoints ) > 0 ;
1203
- foreach ($ throwPoints as $ throwPoint ) {
1204
- $ isSuperType = $ catchType ->isSuperTypeOf ($ throwPoint ->getType ());
1205
- if (!$ hasExplicit && !$ isSuperType ->no ()) {
1206
- $ matchingThrowPoints [] = $ throwPoint ;
1207
- }
1208
- if ($ isSuperType ->yes ()) {
1209
- continue ;
1210
- }
1211
- $ newThrowPoints [] = $ throwPoint ->subtractCatchType ($ catchType );
1202
+ if ($ isSuperType ->yes ()) {
1203
+ continue ;
1212
1204
}
1213
- $ throwPoints = $ newThrowPoints ;
1214
-
1215
- if (count ($ matchingThrowPoints ) === 0 ) {
1216
- $ throwableThrowPoints = [];
1217
- if ($ originalCatchType ->isSuperTypeOf (new ObjectType (\Throwable::class))->yes ()) {
1218
- foreach ($ branchScopeResult ->getThrowPoints () as $ originalThrowPoint ) {
1219
- if (!$ originalThrowPoint ->canContainAnyThrowable ()) {
1220
- continue ;
1221
- }
1205
+ $ newThrowPoints [] = $ throwPoint ->subtractCatchType ($ catchType );
1206
+ }
1207
+ $ throwPoints = $ newThrowPoints ;
1222
1208
1223
- $ throwableThrowPoints [] = $ originalThrowPoint ;
1209
+ if (count ($ matchingThrowPoints ) === 0 ) {
1210
+ $ throwableThrowPoints = [];
1211
+ if ($ originalCatchType ->isSuperTypeOf (new ObjectType (\Throwable::class))->yes ()) {
1212
+ foreach ($ branchScopeResult ->getThrowPoints () as $ originalThrowPoint ) {
1213
+ if (!$ originalThrowPoint ->canContainAnyThrowable ()) {
1214
+ continue ;
1224
1215
}
1225
- }
1226
1216
1227
- if (count ($ throwableThrowPoints ) === 0 ) {
1228
- $ nodeCallback (new CatchWithUnthrownExceptionNode ($ catchNode , $ catchType , $ originalCatchType ), $ scope );
1229
- continue ;
1217
+ $ throwableThrowPoints [] = $ originalThrowPoint ;
1230
1218
}
1231
-
1232
- $ matchingThrowPoints = $ throwableThrowPoints ;
1233
1219
}
1234
1220
1235
- $ catchScope = null ;
1236
- foreach ($ matchingThrowPoints as $ matchingThrowPoint ) {
1237
- if ($ catchScope === null ) {
1238
- $ catchScope = $ matchingThrowPoint ->getScope ();
1239
- } else {
1240
- $ catchScope = $ catchScope ->mergeWith ($ matchingThrowPoint ->getScope ());
1241
- }
1221
+ if (count ($ throwableThrowPoints ) === 0 ) {
1222
+ $ nodeCallback (new CatchWithUnthrownExceptionNode ($ catchNode , $ catchType , $ originalCatchType ), $ scope );
1223
+ continue ;
1242
1224
}
1243
1225
1244
- $ variableName = null ;
1245
- if ($ catchNode ->var !== null ) {
1246
- if (!is_string ($ catchNode ->var ->name )) {
1247
- throw new \PHPStan \ShouldNotHappenException ();
1248
- }
1226
+ $ matchingThrowPoints = $ throwableThrowPoints ;
1227
+ }
1249
1228
1250
- $ variableName = $ catchNode ->var ->name ;
1229
+ $ catchScope = null ;
1230
+ foreach ($ matchingThrowPoints as $ matchingThrowPoint ) {
1231
+ if ($ catchScope === null ) {
1232
+ $ catchScope = $ matchingThrowPoint ->getScope ();
1233
+ } else {
1234
+ $ catchScope = $ catchScope ->mergeWith ($ matchingThrowPoint ->getScope ());
1251
1235
}
1236
+ }
1252
1237
1253
- $ catchScopeResult = $ this ->processStmtNodes ($ catchNode , $ catchNode ->stmts , $ catchScope ->enterCatchType ($ catchType , $ variableName ), $ nodeCallback );
1254
- $ catchScopeForFinally = $ catchScopeResult ->getScope ();
1255
- } else {
1256
- $ initialScope = $ scope ;
1257
- if (count ($ throwPoints ) > 0 ) {
1258
- $ initialScope = $ throwPoints [0 ]->getScope ();
1238
+ $ variableName = null ;
1239
+ if ($ catchNode ->var !== null ) {
1240
+ if (!is_string ($ catchNode ->var ->name )) {
1241
+ throw new \PHPStan \ShouldNotHappenException ();
1259
1242
}
1260
1243
1261
- $ catchScopeForFinally = $ this ->processCatchNode ($ catchNode , $ branchScope , $ nodeCallback )->getScope ();
1262
- $ catchScopeResult = $ this ->processCatchNode ($ catchNode , $ initialScope ->mergeWith ($ branchScope ), static function (): void {
1263
- });
1244
+ $ variableName = $ catchNode ->var ->name ;
1264
1245
}
1265
1246
1247
+ $ catchScopeResult = $ this ->processStmtNodes ($ catchNode , $ catchNode ->stmts , $ catchScope ->enterCatchType ($ catchType , $ variableName ), $ nodeCallback );
1248
+ $ catchScopeForFinally = $ catchScopeResult ->getScope ();
1249
+
1266
1250
$ finalScope = $ catchScopeResult ->isAlwaysTerminating () ? $ finalScope : $ catchScopeResult ->getScope ()->mergeWith ($ finalScope );
1267
1251
$ alwaysTerminating = $ alwaysTerminating && $ catchScopeResult ->isAlwaysTerminating ();
1268
1252
$ hasYield = $ hasYield || $ catchScopeResult ->hasYield ();
@@ -1501,31 +1485,6 @@ private function createAstClassReflection(Node\Stmt\ClassLike $stmt, Scope $scop
1501
1485
);
1502
1486
}
1503
1487
1504
- /**
1505
- * @param Node\Stmt\Catch_ $catchNode
1506
- * @param MutatingScope $catchScope
1507
- * @param callable(\PhpParser\Node $node, Scope $scope): void $nodeCallback
1508
- * @return StatementResult
1509
- */
1510
- private function processCatchNode (
1511
- Node \Stmt \Catch_ $ catchNode ,
1512
- MutatingScope $ catchScope ,
1513
- callable $ nodeCallback
1514
- ): StatementResult
1515
- {
1516
- $ variableName = null ;
1517
- if ($ catchNode ->var !== null ) {
1518
- if (!is_string ($ catchNode ->var ->name )) {
1519
- throw new \PHPStan \ShouldNotHappenException ();
1520
- }
1521
-
1522
- $ variableName = $ catchNode ->var ->name ;
1523
- }
1524
-
1525
- $ catchScope = $ catchScope ->enterCatch ($ catchNode ->types , $ variableName );
1526
- return $ this ->processStmtNodes ($ catchNode , $ catchNode ->stmts , $ catchScope , $ nodeCallback );
1527
- }
1528
-
1529
1488
private function lookForEnterVariableAssign (MutatingScope $ scope , Expr $ expr ): MutatingScope
1530
1489
{
1531
1490
if (!$ expr instanceof ArrayDimFetch || $ expr ->dim !== null ) {
0 commit comments