forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-13332.php
More file actions
65 lines (53 loc) · 1.09 KB
/
Copy pathbug-13332.php
File metadata and controls
65 lines (53 loc) · 1.09 KB
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
63
64
65
<?php // lint >= 8.1
declare(strict_types = 1);
namespace Bug13332;
use function PHPStan\Testing\assertType;
enum TestEnum {
case A;
case B;
}
/**
* @phpstan-type KeyType string|int|\UnitEnum|object
*
* @template K of KeyType
*/
class TestError
{
/** @param K $key */
public function __construct(private readonly mixed $key)
{
}
/** @return self<TestEnum> */
public static function makeEnum(): self
{
return new self(TestEnum::A);
}
/** @return self<string> */
public static function makeString(): self
{
return new self('foo');
}
}
/**
* @template K of string|int|\UnitEnum|object
*/
class TestOk
{
/** @param K $key */
public function __construct(private readonly mixed $key)
{
}
/** @return self<TestEnum> */
public static function makeEnum(): self
{
return new self(TestEnum::A);
}
}
function () {
$error = TestError::makeEnum();
assertType('Bug13332\TestError<Bug13332\TestEnum>', $error);
$errorStr = TestError::makeString();
assertType('Bug13332\TestError<string>', $errorStr);
$ok = TestOk::makeEnum();
assertType('Bug13332\TestOk<Bug13332\TestEnum>', $ok);
};