forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-4971.php
More file actions
62 lines (53 loc) · 908 Bytes
/
bug-4971.php
File metadata and controls
62 lines (53 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php declare(strict_types = 1);
namespace Bug4971;
use function PHPStan\Testing\assertType;
/**
* @template T
*/
interface IFoo
{
/** @param T $v */
public function __construct($v);
}
/**
* @template T
* @implements IFoo<T>
*/
class Foo implements IFoo
{
/** @var T */
private $v; // @phpstan-ignore property.uninitializedReadonly
/**
* @param T $v
*/
public function __construct($v)
{
$this->v = $v;
}
}
/**
* @template T
* @template K of IFoo
* @param T $v
* @param class-string<K> $class
* @return K
*/
function make1($v, string $class)
{
return new $class($v);
}
/**
* @template T
* @template K of IFoo
* @param T $v
* @param class-string<K> $class
* @return K<T>
*/
function make2($v, string $class)
{
return new $class($v);
}
$obj1 = make1(1, Foo::class);
assertType('Bug4971\Foo', $obj1);
$obj2 = make2(1, Foo::class);
assertType('Bug4971\Foo<int>', $obj2);