Skip to content

Commit d6c9c27

Browse files
committed
Testcase for intersection of a class and a separate interface after instanceof
1 parent 8ae2a43 commit d6c9c27

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,6 +2033,14 @@ public function dataInstanceOf(): array
20332033
'static(InstanceOfNamespace\Foo)',
20342034
'clone $static',
20352035
],
2036+
[
2037+
'InstanceOfNamespace\BarInterface&InstanceOfNamespace\Foo',
2038+
'$intersected',
2039+
],
2040+
[
2041+
'$this(InstanceOfNamespace\Foo)&InstanceOfNamespace\BarInterface',
2042+
'$this',
2043+
],
20362044
];
20372045
}
20382046

tests/PHPStan/Analyser/data/instanceof.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
use PhpParser\Node\Expr;
66
use PhpParser\Node\Expr\ArrayDimFetch;
77

8+
interface BarInterface
9+
{
10+
11+
}
12+
813
class Foo
914
{
1015

1116
public function someMethod(Expr $foo)
1217
{
1318
$bar = $foo;
1419
$baz = doFoo();
20+
$intersected = new Foo();
1521

1622
if ($baz instanceof Foo) {
1723
// ...
@@ -21,7 +27,11 @@ public function someMethod(Expr $foo)
2127
if ($dolor instanceof Dolor && $sit instanceof Sit) {
2228
if ($static instanceof static) {
2329
if ($self instanceof self) {
24-
die;
30+
if ($intersected instanceof BarInterface) {
31+
if ($this instanceof BarInterface) {
32+
die;
33+
}
34+
}
2535
}
2636
}
2737
}

0 commit comments

Comments
 (0)