File tree Expand file tree Collapse file tree
tests/PHPStan/Rules/Exceptions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -799,7 +799,15 @@ public function testBug6574(): void
799799 $ this ->analyse ([__DIR__ . '/data/bug-6574.php ' ], [
800800 [
801801 'Dead catch - Exception is never thrown in the try block. ' ,
802- 83 ,
802+ 97 ,
803+ ],
804+ [
805+ 'Dead catch - Exception is never thrown in the try block. ' ,
806+ 106 ,
807+ ],
808+ [
809+ 'Dead catch - Exception is never thrown in the try block. ' ,
810+ 115 ,
803811 ],
804812 ]);
805813 }
Original file line number Diff line number Diff line change @@ -30,6 +30,20 @@ final class FinalClass
3030{
3131}
3232
33+ interface ThrowsVoidInterface
34+ {
35+ /** @throws void */
36+ public function __construct ();
37+ }
38+
39+ abstract class AbstractThrowsVoid
40+ {
41+ /** @throws void */
42+ public function __construct ()
43+ {
44+ }
45+ }
46+
3347/** @param class-string<FooInterface> $class */
3448function interfaceWithoutConstructor (string $ class ): void
3549{
@@ -83,3 +97,21 @@ function finalClassWithoutConstructor(string $class): void
8397 } catch (\Exception $ e ) { // dead catch - final class with no constructor
8498 }
8599}
100+
101+ /** @param class-string<ThrowsVoidInterface> $class */
102+ function interfaceWithThrowsVoidConstructor (string $ class ): void
103+ {
104+ try {
105+ new $ class ();
106+ } catch (\Exception $ e ) { // dead catch - constructor is @throws void
107+ }
108+ }
109+
110+ /** @param class-string<AbstractThrowsVoid> $class */
111+ function abstractClassWithThrowsVoidConstructor (string $ class ): void
112+ {
113+ try {
114+ new $ class ();
115+ } catch (\Exception $ e ) { // dead catch - constructor is @throws void
116+ }
117+ }
You can’t perform that action at this time.
0 commit comments