Skip to content

Commit

Permalink
TemplateMixedType::equals() - do not compare subtracted types
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Dec 13, 2019
1 parent 41db2c9 commit ff7311a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Type/Generic/TemplateMixedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public function equals(Type $type): bool
{
return $type instanceof self
&& $type->scope->equals($this->scope)
&& $type->name === $this->name
&& parent::equals($type);
&& $type->name === $this->name;
}

public function getBound(): Type
Expand Down
60 changes: 60 additions & 0 deletions tests/PHPStan/Rules/Generators/data/yield.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,63 @@ public function doArrayShape(): \Generator
}

}

/**
* @template TKey
* @template TValue
*/
final class Map
{
/** @var TKey */
private $key;
/** @var TValue */
private $value;

/**
* @param TKey $key
* @param TValue $value
*/
public function __construct($key, $value)
{
$this->key = $key;
$this->value = $value;
}

/** @return TKey */
public function key()
{
return $this->key;
}

/** @return TValue */
public function value()
{
return $this->value;
}
}

class TestMap
{

/**
* @template TKey
* @template TValue
*
* @param iterable<TKey, TValue> $iterator
* @param callable(TValue, TKey):(TValue|Map<TKey, TValue>) $callback
*
* @return iterable<TKey, TValue>
*/
function iterator_map(iterable $iterator, callable $callback): iterable
{
foreach ($iterator as $key => $value) {
$result = $callback($value, $key);
if ($result instanceof Map) {
yield $result->key() => $result->value();
continue;
}
yield $key => $result;
}
}

}

0 comments on commit ff7311a

Please sign in to comment.