Skip to content

Commit 92994d6

Browse files
committed
Regression test
Closes phpstan/phpstan#2723
1 parent 936cea5 commit 92994d6

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,15 @@ public function testBug2568(): void
8989
$this->analyse([__DIR__ . '/data/bug-2568.php'], []);
9090
}
9191

92+
public function testBug2723(): void
93+
{
94+
require_once __DIR__ . '/data/bug-2723.php';
95+
$this->analyse([__DIR__ . '/data/bug-2723.php'], [
96+
[
97+
'Function Bug2723\baz() should return Bug2723\Bar<Bug2723\Foo<T4>> but returns Bug2723\BarOfFoo<string>.',
98+
55,
99+
],
100+
]);
101+
}
102+
92103
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Bug2723;
4+
5+
/**
6+
* @template T1
7+
*/
8+
class Foo
9+
{
10+
/** @var T1 */
11+
public $t;
12+
13+
/** @param T1 $t */
14+
public function __construct($t)
15+
{
16+
$this->t = $t;
17+
}
18+
}
19+
20+
/**
21+
* @template T2
22+
*/
23+
class Bar
24+
{
25+
/** @var T2 */
26+
public $t;
27+
28+
/** @param T2 $t */
29+
public function __construct($t)
30+
{
31+
$this->t = $t;
32+
}
33+
}
34+
35+
/**
36+
* @template T3
37+
* @extends Bar<Foo<T3>>
38+
*/
39+
class BarOfFoo extends Bar
40+
{
41+
/** @param T3 $t */
42+
public function __construct($t)
43+
{
44+
parent::__construct(new Foo($t));
45+
}
46+
}
47+
48+
/**
49+
* @template T4
50+
* @param T4 $t
51+
* @return Bar<Foo<T4>>
52+
*/
53+
function baz($t)
54+
{
55+
return new BarOfFoo("hello");
56+
}
57+
58+
/**
59+
* @template T4
60+
* @param T4 $t
61+
* @return Bar<Foo<T4>>
62+
*/
63+
function baz2($t)
64+
{
65+
return new BarOfFoo($t);
66+
}

0 commit comments

Comments
 (0)