Skip to content

Commit

Permalink
Regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 20, 2022
1 parent b1069e1 commit 98ab8c9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Expand Up @@ -915,6 +915,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/constant-array-intersect.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7153.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/in-array-non-empty.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4117.php');
}

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

namespace Bug4117Types;

use ArrayIterator;
use IteratorAggregate;
use function PHPStan\Testing\assertType;

/**
* @refactor Refactor utils into base library
* @template T of mixed
* @implements IteratorAggregate<int, T>
*/
class GenericList implements IteratorAggregate
{
/** @var array<int, T> */
protected $items = [];

/**
* @return ArrayIterator<int, T>
*/
public function getIterator(): ArrayIterator
{
return new ArrayIterator($this->items);
}

/**
* @return ?T
*/
public function broken(int $key)
{
$item = $this->items[$key] ?? null;
if ($item) {
assertType("T of mixed~0|0.0|''|'0'|array{}|false|null (class Bug4117Types\GenericList, argument)", $item);
} else {
assertType("(array{}&T (class Bug4117Types\GenericList, argument))|(0.0&T (class Bug4117Types\GenericList, argument))|(0&T (class Bug4117Types\GenericList, argument))|(''&T (class Bug4117Types\GenericList, argument))|('0'&T (class Bug4117Types\GenericList, argument))|(T (class Bug4117Types\GenericList, argument)&false)|null", $item);
}

assertType("T of mixed~0|0.0|''|'0'|array{}|false|null (class Bug4117Types\GenericList, argument)|null", $item);

return $item;
}

/**
* @return ?T
*/
public function works(int $key)
{
$item = $this->items[$key] ?? null;
assertType('T (class Bug4117Types\GenericList, argument)|null', $item);

return $item;
}
}

0 comments on commit 98ab8c9

Please sign in to comment.