Skip to content

Commit 8430805

Browse files
committed
[BE] Report dead types even in multi-exception catch
1 parent ee565db commit 8430805

10 files changed

+5
-69
lines changed

changelog-2.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ Bleeding edge (TODO move to other sections)
5858
* More precise `file()` flags args ([#2476](https://github.com/phpstan/phpstan-src/pull/2476), [#2482](https://github.com/phpstan/phpstan-src/pull/2482)), thanks @staabm!
5959
* More precise `flock()` operation flags ([#2477](https://github.com/phpstan/phpstan-src/pull/2477)), thanks @staabm!
6060
* Rule for `call_user_func()` ([#2479](https://github.com/phpstan/phpstan-src/pull/2479)), thanks @staabm!
61-
* Report dead types even in multi-exception catch ([#2399](https://github.com/phpstan/phpstan-src/pull/2399)), thanks @JanTvrdik!
6261
* `error_log` errors with `message_type=2` ([#2428](https://github.com/phpstan/phpstan-src/pull/2428)), #9380, thanks @staabm!
6362
* Check `filter_input*` type param type ([#2271](https://github.com/phpstan/phpstan-src/pull/2271)), thanks @herndlm!
6463
* More precise `stream_socket_client()` signature ([#2519](https://github.com/phpstan/phpstan-src/pull/2519)), thanks @staabm!
@@ -139,6 +138,7 @@ Improvements 🔧
139138
* Consider implicit throw points when the only explicit one is `Throw_` (https://github.com/phpstan/phpstan-src/commit/22eef6d5ab9a4afafb2305258fea273be6cc06e4), #4912
140139
* Run missing type check on `@param-out` (https://github.com/phpstan/phpstan-src/commit/56b20024386d983927c64dfa895ff026bed2798c)
141140
* Report "missing return" error closer to where the return is missing (https://github.com/phpstan/phpstan-src/commit/04f8636e6577cbcaefc944725eed74c0d7865ead)
141+
* Report dead types even in multi-exception catch ([#2399](https://github.com/phpstan/phpstan-src/pull/2399)), thanks @JanTvrdik!
142142

143143
Bugfixes 🐛
144144
=====================

conf/bleedingEdge.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ parameters:
3535
propertyVariance: true
3636
genericPrototypeMessage: true
3737
stricterFunctionMap: true
38-
detectDeadTypeInMultiCatch: true
3938
zeroFiles: true
4039
projectServicesNotInAnalysedPaths: true
4140
callUserFunc: true

conf/config.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ parameters:
7171
propertyVariance: false
7272
genericPrototypeMessage: false
7373
stricterFunctionMap: false
74-
detectDeadTypeInMultiCatch: false
7574
zeroFiles: false
7675
projectServicesNotInAnalysedPaths: false
7776
callUserFunc: false
@@ -527,7 +526,6 @@ services:
527526
earlyTerminatingFunctionCalls: %earlyTerminatingFunctionCalls%
528527
implicitThrows: %exceptions.implicitThrows%
529528
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
530-
detectDeadTypeInMultiCatch: %featureToggles.detectDeadTypeInMultiCatch%
531529
universalObjectCratesClasses: %universalObjectCratesClasses%
532530

533531
-

conf/parametersSchema.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ parametersSchema:
6565
propertyVariance: bool()
6666
genericPrototypeMessage: bool()
6767
stricterFunctionMap: bool()
68-
detectDeadTypeInMultiCatch: bool()
6968
zeroFiles: bool()
7069
projectServicesNotInAnalysedPaths: bool()
7170
callUserFunc: bool()

src/Analyser/NodeScopeResolver.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ public function __construct(
259259
private readonly array $universalObjectCratesClasses,
260260
private readonly bool $implicitThrows,
261261
private readonly bool $treatPhpDocTypesAsCertain,
262-
private readonly bool $detectDeadTypeInMultiCatch,
263262
)
264263
{
265264
$earlyTerminatingMethodNames = [];
@@ -1593,19 +1592,14 @@ private function processStmtNode(
15931592
}
15941593

15951594
// emit error
1596-
if ($this->detectDeadTypeInMultiCatch) {
1597-
foreach ($matchingCatchTypes as $catchTypeIndex => $matched) {
1598-
if ($matched) {
1599-
continue;
1600-
}
1601-
$nodeCallback(new CatchWithUnthrownExceptionNode($catchNode, $catchTypes[$catchTypeIndex], $originalCatchTypes[$catchTypeIndex]), $scope);
1595+
foreach ($matchingCatchTypes as $catchTypeIndex => $matched) {
1596+
if ($matched) {
1597+
continue;
16021598
}
1599+
$nodeCallback(new CatchWithUnthrownExceptionNode($catchNode, $catchTypes[$catchTypeIndex], $originalCatchTypes[$catchTypeIndex]), $scope);
16031600
}
16041601

16051602
if (count($matchingThrowPoints) === 0) {
1606-
if (!$this->detectDeadTypeInMultiCatch) {
1607-
$nodeCallback(new CatchWithUnthrownExceptionNode($catchNode, $catchType, $originalCatchType), $scope);
1608-
}
16091603
continue;
16101604
}
16111605

src/Testing/RuleTestCase.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ private function getAnalyser(DirectRuleRegistry $ruleRegistry): Analyser
105105
self::getContainer()->getParameter('universalObjectCratesClasses'),
106106
self::getContainer()->getParameter('exceptions')['implicitThrows'],
107107
$this->shouldTreatPhpDocTypesAsCertain(),
108-
self::getContainer()->getParameter('featureToggles')['detectDeadTypeInMultiCatch'],
109108
);
110109
$fileAnalyser = new FileAnalyser(
111110
$this->createScopeFactory($reflectionProvider, $typeSpecifier),

src/Testing/TypeInferenceTestCase.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ public static function processFile(
8585
self::getContainer()->getParameter('universalObjectCratesClasses'),
8686
self::getContainer()->getParameter('exceptions')['implicitThrows'],
8787
self::getContainer()->getParameter('treatPhpDocTypesAsCertain'),
88-
self::getContainer()->getParameter('featureToggles')['detectDeadTypeInMultiCatch'],
8988
);
9089
$resolver->setAnalysedFiles(array_map(static fn (string $file): string => $fileHelper->normalizePath($file), array_merge([$file], static::getAdditionalAnalysedFiles())));
9190

tests/PHPStan/Analyser/AnalyserTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,6 @@ private function createAnalyser(): Analyser
728728
[stdClass::class],
729729
true,
730730
$this->shouldTreatPhpDocTypesAsCertain(),
731-
self::getContainer()->getParameter('featureToggles')['detectDeadTypeInMultiCatch'],
732731
);
733732
$lexer = new Lexer();
734733
$fileAnalyser = new FileAnalyser(

tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleWithDisabledMultiCatchTest.php

Lines changed: 0 additions & 48 deletions
This file was deleted.

tests/PHPStan/Rules/Exceptions/disable-detect-multi-catch.neon

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)