File tree Expand file tree Collapse file tree 4 files changed +87
-1
lines changed Expand file tree Collapse file tree 4 files changed +87
-1
lines changed Original file line number Diff line number Diff line change @@ -1170,7 +1170,7 @@ private function processStmtNode(
1170
1170
$ matchingThrowPoints = [];
1171
1171
$ newThrowPoints = [];
1172
1172
foreach ($ throwPoints as $ throwPoint ) {
1173
- if (!$ throwPoint ->isExplicit ()) {
1173
+ if (!$ throwPoint ->isExplicit () && ! $ catchType -> isSuperTypeOf ( new ObjectType (\Throwable::class))-> yes () ) {
1174
1174
continue ;
1175
1175
}
1176
1176
$ isSuperType = $ catchType ->isSuperTypeOf ($ throwPoint ->getType ());
Original file line number Diff line number Diff line change @@ -385,6 +385,8 @@ public function dataFileAsserts(): iterable
385
385
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/DateTimeDynamicReturnTypes.php ' );
386
386
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-4821.php ' );
387
387
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-4838.php ' );
388
+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-4879.php ' );
389
+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-4820.php ' );
388
390
}
389
391
390
392
/**
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Bug4820 ;
4
+
5
+ use PHPStan \TrinaryLogic ;
6
+ use function PHPStan \Testing \assertType ;
7
+ use function PHPStan \Testing \assertVariableCertainty ;
8
+
9
+ class Param {
10
+
11
+ public bool $ foo ;
12
+ }
13
+
14
+ class HelloWorld
15
+ {
16
+ public function sayHello (Param $ param ): void
17
+ {
18
+
19
+ try {
20
+ $ result = call_user_func ([$ this , 'mayThrow ' ]);
21
+ if ($ param ->foo ) {
22
+ $ this ->mayThrow ();
23
+ }
24
+
25
+ } catch (\Throwable $ e ) {
26
+ assertType ('bool ' , $ param ->foo );
27
+ assertVariableCertainty (TrinaryLogic::createMaybe (), $ result );
28
+ throw $ e ;
29
+ }
30
+ }
31
+
32
+ /**
33
+ * @throws \RuntimeException
34
+ */
35
+ private function mayThrow (): void
36
+ {
37
+ throw new \RuntimeException ();
38
+ }
39
+
40
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Bug4879 ;
4
+
5
+ use PHPStan \TrinaryLogic ;
6
+ use function PHPStan \Testing \assertVariableCertainty ;
7
+
8
+ class HelloWorld
9
+ {
10
+ public function sayHello (bool $ bool1 ): void
11
+ {
12
+ try {
13
+ if ($ bool1 ) {
14
+ throw new \Exception ();
15
+ }
16
+
17
+ $ var = 'foo ' ;
18
+
19
+ $ this ->test ();
20
+ } catch (\Throwable $ ex ) {
21
+ assertVariableCertainty (TrinaryLogic::createMaybe (), $ var );
22
+ }
23
+ }
24
+
25
+ public function sayHello2 (bool $ bool1 ): void
26
+ {
27
+ try {
28
+ if ($ bool1 ) {
29
+ throw new \Exception ();
30
+ }
31
+
32
+ $ var = 'foo ' ;
33
+
34
+ $ this ->test ();
35
+ } catch (\Exception $ ex ) {
36
+ assertVariableCertainty (TrinaryLogic::createNo (), $ var );
37
+ }
38
+ }
39
+
40
+ public function test (): void
41
+ {
42
+ return ;
43
+ }
44
+ }
You can’t perform that action at this time.
0 commit comments