File tree Expand file tree Collapse file tree
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php // lint >= 8.1
2+
3+ declare (strict_types = 1 );
4+
5+ namespace Bug13332 ;
6+
7+ use function PHPStan \Testing \assertType ;
8+
9+ enum TestEnum {
10+ case A;
11+ case B;
12+ }
13+
14+ /**
15+ * @phpstan-type KeyType string|int|\UnitEnum|object
16+ *
17+ * @template K of KeyType
18+ */
19+ class TestError
20+ {
21+ /** @param K $key */
22+ public function __construct (private readonly mixed $ key )
23+ {
24+ }
25+
26+ /** @return self<TestEnum> */
27+ public static function makeEnum (): self
28+ {
29+ return new self (TestEnum::A);
30+ }
31+
32+ /** @return self<string> */
33+ public static function makeString (): self
34+ {
35+ return new self ('foo ' );
36+ }
37+ }
38+
39+ /**
40+ * @template K of string|int|\UnitEnum|object
41+ */
42+ class TestOk
43+ {
44+ /** @param K $key */
45+ public function __construct (private readonly mixed $ key )
46+ {
47+ }
48+
49+ /** @return self<TestEnum> */
50+ public static function makeEnum (): self
51+ {
52+ return new self (TestEnum::A);
53+ }
54+ }
55+
56+ function () {
57+ $ error = TestError::makeEnum ();
58+ assertType ('Bug13332\TestError<Bug13332\TestEnum> ' , $ error );
59+
60+ $ errorStr = TestError::makeString ();
61+ assertType ('Bug13332\TestError<string> ' , $ errorStr );
62+
63+ $ ok = TestOk::makeEnum ();
64+ assertType ('Bug13332\TestOk<Bug13332\TestEnum> ' , $ ok );
65+ };
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Bug7152 ;
4+
5+ use function PHPStan \Testing \assertType ;
6+
7+ /**
8+ * @template T of array<mixed>
9+ */
10+ class Root
11+ {
12+ /** @var T */
13+ public array $ value ;
14+ }
15+
16+ /**
17+ * @phpstan-type Foo array<int>
18+ * @template T of Foo
19+ * @extends Root<T>
20+ */
21+ class Middle extends Root
22+ {
23+ }
24+
25+ /**
26+ * @template T of array<int>
27+ * @extends Root<T>
28+ */
29+ class Middle2 extends Root
30+ {
31+ }
32+
33+ function () {
34+ /** @var Middle<array<int>> $m */
35+ $ m = new Middle ();
36+ assertType ('array<int> ' , $ m ->value );
37+
38+ /** @var Middle2<array<int>> $m2 */
39+ $ m2 = new Middle2 ();
40+ assertType ('array<int> ' , $ m2 ->value );
41+ };
You can’t perform that action at this time.
0 commit comments