Skip to content

Commit f015f24

Browse files
phpstan-botclaude
authored andcommitted
Add regression tests for phpstan/phpstan#7185 and phpstan/phpstan#13204
Both issues involve template bounds not being correctly resolved when generic types are used without explicit type parameters. These are now fixed by the getActiveTemplateTypeMapForAncestorResolution() change. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8970316 commit f015f24

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug13204;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @template TChild of object
9+
* @extends \ArrayAccess<int, TChild|null>
10+
*/
11+
interface ParentNode extends \ArrayAccess {}
12+
13+
class HelloWorld
14+
{
15+
public function sayHelloBug(object $node): void
16+
{
17+
if ($node instanceof ParentNode) {
18+
assertType('object|null', $node[0]);
19+
}
20+
}
21+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug7185;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @template TKey of array-key
9+
* @template TValue of object
10+
* @extends \IteratorAggregate<TKey, TValue>
11+
*/
12+
interface Collection extends \IteratorAggregate {}
13+
14+
function foo(Collection $list): void {
15+
$all = iterator_to_array($list);
16+
assertType('array<object>', $all);
17+
assertType('object|false', current($all));
18+
}

0 commit comments

Comments
 (0)