Skip to content

Commit d7e82b3

Browse files
committed
Merge branch '1.4.x'
2 parents 4251d25 + dfc5d25 commit d7e82b3

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+

0 commit comments

Comments
 (0)