Skip to content

Commit ff70090

Browse files
authored
Add regression test for #12820 (#6836)
1 parent a51e744 commit ff70090

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

‎tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4560,6 +4560,15 @@ public function testBug15251(): void
45604560
$this->analyse([__DIR__ . '/data/bug-15251.php'], []);
45614561
}
45624562

4563+
#[RequiresPhp('>= 8.0.0')]
4564+
public function testBug12820(): void
4565+
{
4566+
$this->checkThisOnly = false;
4567+
$this->checkNullables = true;
4568+
$this->checkUnionTypes = true;
4569+
$this->analyse([__DIR__ . '/data/bug-12820.php'], []);
4570+
}
4571+
45634572
#[RequiresPhp('>= 8.1.0')]
45644573
public function testClassConstantWildcardArguments(): void
45654574
{
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php // lint >= 8.0
2+
3+
declare(strict_types = 1);
4+
5+
namespace Bug12820;
6+
7+
class A
8+
{
9+
10+
public function a(): void
11+
{
12+
}
13+
14+
}
15+
16+
class B
17+
{
18+
19+
}
20+
21+
/** @template-covariant T of A|B = A|B */
22+
interface FooInterface
23+
{
24+
25+
/**
26+
* @phpstan-assert-if-true static<A> $this
27+
*/
28+
public function isA(): bool;
29+
30+
/** @return T */
31+
public function get(): A|B;
32+
33+
}
34+
35+
/**
36+
* @template-covariant T of A|B = A|B
37+
* @implements FooInterface<T>
38+
*/
39+
abstract class Foo implements FooInterface
40+
{
41+
42+
public function other(): void
43+
{
44+
if ($this->isA()) {
45+
$this->get()->a();
46+
}
47+
}
48+
49+
}

0 commit comments

Comments
 (0)