Skip to content

Commit 8175b6e

Browse files
committed
Regression test
Closes phpstan/phpstan#10353
1 parent 43c2d27 commit 8175b6e

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

tests/PHPStan/Rules/Classes/ImpossibleInstanceOfRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,12 @@ public function testBug10036(): void
546546
]);
547547
}
548548

549+
public function testBug10353(): void
550+
{
551+
$this->treatPhpDocTypesAsCertain = true;
552+
$this->analyse([__DIR__ . '/data/bug-10353.php'], []);
553+
}
554+
549555
public function testBug12267(): void
550556
{
551557
$this->treatPhpDocTypesAsCertain = true;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug10353;
4+
5+
trait Foo
6+
{
7+
public function test(): string
8+
{
9+
if ($this instanceof HelloWorld) {
10+
return 'hello world';
11+
}
12+
if ($this instanceof OtherClass) {
13+
return 'other class';
14+
}
15+
throw new \Error();
16+
}
17+
}
18+
19+
class HelloWorld
20+
{
21+
use Foo;
22+
23+
function bar(): string
24+
{
25+
return $this->test();
26+
}
27+
}
28+
29+
class OtherClass
30+
{
31+
use Foo;
32+
33+
function bar(): string
34+
{
35+
return $this->test();
36+
}
37+
}

0 commit comments

Comments
 (0)