Skip to content
Draft
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b973b5f
first pass
shmax Apr 1, 2026
eb67c21
enforce required generic params
shmax Apr 1, 2026
6fdb88f
more tests
shmax Apr 1, 2026
b27d26e
tests for invalud usage
shmax Apr 1, 2026
4f18071
fix regression
shmax Apr 1, 2026
95abc98
add more scenarios to test fixture
shmax Apr 1, 2026
f529784
remove empty patch
shmax Apr 1, 2026
590daa6
coalesce to empty array
shmax Apr 1, 2026
b8e0c55
lint
shmax Apr 1, 2026
a94b14b
fix use function ordering
shmax Apr 1, 2026
beedafb
fix generic alias resolution: skip alias path when name resolves to a…
shmax Apr 1, 2026
e023f92
remove resolveWithDefaults: bare generic alias usage restores old Tem…
shmax Apr 1, 2026
04c8aec
fix phpstan self-analysis errors: ignore property.notFound, add null …
shmax Apr 1, 2026
0195d7d
remove ignore
shmax Apr 1, 2026
95ae9e4
add property.notFound baseline entry for PHP < 8.0 (phpdoc-parser lac…
shmax Apr 1, 2026
2fd32f3
move property.notFound baseline entry to universal phpstan-baseline.n…
shmax Apr 1, 2026
89423b3
fix generic alias bare-usage resolution and data-provider parameter s…
shmax Apr 2, 2026
6c7322d
update baseline after rebase onto 2.1.x
shmax Apr 2, 2026
2321f59
add temp patches
shmax Apr 2, 2026
5726a40
use LateResolvableType
shmax Apr 2, 2026
6426482
remove
shmax Apr 2, 2026
fb9203b
lint
shmax Apr 2, 2026
d7fe98c
fix array vs list error
shmax Apr 2, 2026
e3aebe9
remove dead code
shmax Apr 2, 2026
ef31211
fold getRawGenericTypeAliasesUsage into getNonGenericObjectTypesWithG…
shmax Apr 15, 2026
106b589
update lock hash
shmax Apr 15, 2026
45ba91b
lint
shmax Apr 15, 2026
57a2395
remove unnecessary BC coverage from generic type alias resolution
shmax Apr 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add more scenarios to test fixture
  • Loading branch information
shmax committed Apr 15, 2026
commit 95abc98117c92fe5bcd9f85763fcd9d52b04dfff
107 changes: 100 additions & 7 deletions tests/PHPStan/Analyser/nsrt/generic-type-aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,70 @@ public function find(array $request): void
}
}

// -------------------------------------------------------
// Two template params
// -------------------------------------------------------

/**
* @phpstan-type Pair<TFirst, TSecond> array{first: TFirst, second: TSecond}
*/
class PairHolder
{
/**
* @param Pair<string, int> $pair
*/
public function check(array $pair): void
{
assertType('string', $pair['first']);
assertType('int', $pair['second']);
}
}

// -------------------------------------------------------
// @return of generic alias with bound constraint
// -------------------------------------------------------

/**
* @phpstan-type Range<T of int|float> array{min: T, max: T}
*/
class RangeHolder
{
/**
* @param Range<int> $r
* @return Range<float>
*/
public function convert(array $r): array
{
assertType('int', $r['min']);
assertType('int', $r['max']);
$result = ['min' => (float) $r['min'], 'max' => (float) $r['max']];
assertType('array{min: float, max: float}', $result);
return $result;
}
}

// -------------------------------------------------------
// @var property annotation
// -------------------------------------------------------

/**
* @phpstan-type Config<TValue> array{key: string, value: TValue}
*/
class Settings
{
/** @var Config<int> */
public array $timeout = ['key' => 'timeout', 'value' => 30];

/** @var Config<string> */
public array $name = ['key' => 'name', 'value' => 'default'];

public function check(): void
{
assertType('int', $this->timeout['value']);
assertType('string', $this->name['value']);
}
}

// -------------------------------------------------------
// Test with list<T>
// -------------------------------------------------------
Expand All @@ -75,6 +139,25 @@ public function check(array $result): void
}
}

// -------------------------------------------------------
// Nested generic alias (alias referencing another generic alias)
// -------------------------------------------------------

/**
* @phpstan-type Item<T> array{id: int, data: T}
* @phpstan-type ItemList<T> list<Item<T>>
*/
class ItemRepo
{
/**
* @param ItemList<string> $items
*/
public function process(array $items): void
{
assertType('list<array{id: int, data: string}>', $items);
}
}

// -------------------------------------------------------
// Test with two template params
// -------------------------------------------------------
Expand All @@ -94,7 +177,7 @@ public function check(array $m): void
}

// -------------------------------------------------------
// Test with default template param value
// Default param: explicit arg vs bare usage (default applied)
// -------------------------------------------------------

/**
Expand All @@ -103,21 +186,24 @@ public function check(array $m): void
class DefaultHolder
{
/**
* @param WithDefault<int> $withInt
* @param WithDefault<int> $explicit explicit arg overrides default
* @param WithDefault $implicit bare usage – T defaults to string
*/
public function check(array $withInt): void
public function check(array $explicit, array $implicit): void
{
assertType('int', $withInt['value']);
assertType('int', $explicit['value']);
assertType('string', $implicit['value']);
}
}

// -------------------------------------------------------
// Test @phpstan-import-type of a generic alias
// @phpstan-import-type of a generic alias
// -------------------------------------------------------

/**
* @phpstan-import-type Map from MapHolder
* @phpstan-import-type Paged from Repo
* @phpstan-import-type Pair from PairHolder
*/
class ImportConsumer
{
Expand All @@ -137,6 +223,13 @@ public function pagedCheck(array $p): void
assertType('list<DateTime>', $p['items']);
assertType('int', $p['total']);
}
}


/**
* @param Pair<int, bool> $p
*/
public function pairCheck(array $p): void
{
assertType('int', $p['first']);
assertType('bool', $p['second']);
}
}