File tree Expand file tree Collapse file tree 3 files changed +80
-0
lines changed
tests/PHPStan/Rules/Exceptions Expand file tree Collapse file tree 3 files changed +80
-0
lines changed Original file line number Diff line number Diff line change @@ -289,4 +289,31 @@ public function testBug6791(): void
289289 ]);
290290 }
291291
292+ public function testBug6786 (): void
293+ {
294+ if (PHP_VERSION_ID < 70400 ) {
295+ self ::markTestSkipped ('Test requires PHP 7.4. ' );
296+ }
297+
298+ $ this ->analyse ([__DIR__ . '/data/bug-6786.php ' ], []);
299+ }
300+
301+ public function testUnionTypeError (): void
302+ {
303+ if (PHP_VERSION_ID < 80000 ) {
304+ self ::markTestSkipped ('Test requires PHP 8.0. ' );
305+ }
306+
307+ $ this ->analyse ([__DIR__ . '/data/union-type-error.php ' ], [
308+ [
309+ 'Dead catch - TypeError is never thrown in the try block. ' ,
310+ 14 ,
311+ ],
312+ [
313+ 'Dead catch - TypeError is never thrown in the try block. ' ,
314+ 22 ,
315+ ],
316+ ]);
317+ }
318+
292319}
Original file line number Diff line number Diff line change 1+ <?php // lint >= 7.4
2+
3+ declare (strict_types = 1 );
4+
5+ namespace Bug6786 ;
6+
7+ class HelloWorld
8+ {
9+ protected int $ id ;
10+ protected string $ code ;
11+ protected bool $ suggest ;
12+
13+ /**
14+ * @param array|mixed[] $row
15+ * @return void
16+ */
17+ protected function mapping (array $ row ): void
18+ {
19+ $ this ->id = (int ) $ row ['id ' ];
20+ $ this ->code = $ row ['code ' ];
21+ $ this ->suggest = (bool ) $ row ['suggest ' ];
22+ }
23+
24+ }
Original file line number Diff line number Diff line change 1+ <?php // lint >= 8.0
2+
3+ declare (strict_types = 1 );
4+
5+ namespace UnionTypeError ;
6+
7+ class Foo {
8+ public string |int $ stringOrInt ;
9+ public string |array $ stringOrArray ;
10+
11+ public function bar () {
12+ try {
13+ $ this ->stringOrInt = "" ;
14+ } catch (\TypeError $ e ) {}
15+
16+ try {
17+ $ this ->stringOrInt = true ;
18+ } catch (\TypeError $ e ) {}
19+
20+ try {
21+ $ this ->stringOrArray = [];
22+ } catch (\TypeError $ e ) {}
23+
24+ try {
25+ $ this ->stringOrInt = $ this ->stringOrArray ;
26+ } catch (\TypeError $ e ) {}
27+ }
28+ }
29+
You can’t perform that action at this time.
0 commit comments