Skip to content

Commit

Permalink
Regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Oct 3, 2022
1 parent c052aac commit bb8d661
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Expand Up @@ -1049,6 +1049,7 @@ public function dataFileAsserts(): iterable
}

yield from $this->gatherAssertTypes(__DIR__ . '/data/array-offset-unset.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-8008.php');
}

/**
Expand Down
61 changes: 61 additions & 0 deletions tests/PHPStan/Analyser/data/bug-8008.php
@@ -0,0 +1,61 @@
<?php

namespace Bug8008;

use function \PHPStan\Testing\assertType;

/**
* @template TValue
*/
class Collection
{
/**
* @param array<TValue> $items
*/
public function __construct(
public array $items,
) {
}

/**
* @return array<TValue>
*/
public function all() {
return $this->items;
}
}

/**
* @template TValue of object
*
* @mixin Collection<TValue>
*/
class Paginator
{
/**
* @var Collection<TValue>
*/
public Collection $collection;

/**
* @param array<TValue> $items
*/
public function __construct(public array $items)
{
$this->collection = new Collection($items);
}
}

class MyObject {}


function (): void {
$paginator = new Paginator([new MyObject()]);

assertType('Bug8008\Paginator<Bug8008\MyObject>', $paginator);
assertType('array<Bug8008\MyObject>', $paginator->items);
assertType('Bug8008\Collection<Bug8008\MyObject>', $paginator->collection);
assertType('array<Bug8008\MyObject>', $paginator->collection->items);

assertType('array<Bug8008\MyObject>', $paginator->all());
};

0 comments on commit bb8d661

Please sign in to comment.