Skip to content

Commit ff7311a

Browse files
committed
TemplateMixedType::equals() - do not compare subtracted types
1 parent 41db2c9 commit ff7311a

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

src/Type/Generic/TemplateMixedType.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ public function equals(Type $type): bool
7575
{
7676
return $type instanceof self
7777
&& $type->scope->equals($this->scope)
78-
&& $type->name === $this->name
79-
&& parent::equals($type);
78+
&& $type->name === $this->name;
8079
}
8180

8281
public function getBound(): Type

tests/PHPStan/Rules/Generators/data/yield.php

+60
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,63 @@ public function doArrayShape(): \Generator
3131
}
3232

3333
}
34+
35+
/**
36+
* @template TKey
37+
* @template TValue
38+
*/
39+
final class Map
40+
{
41+
/** @var TKey */
42+
private $key;
43+
/** @var TValue */
44+
private $value;
45+
46+
/**
47+
* @param TKey $key
48+
* @param TValue $value
49+
*/
50+
public function __construct($key, $value)
51+
{
52+
$this->key = $key;
53+
$this->value = $value;
54+
}
55+
56+
/** @return TKey */
57+
public function key()
58+
{
59+
return $this->key;
60+
}
61+
62+
/** @return TValue */
63+
public function value()
64+
{
65+
return $this->value;
66+
}
67+
}
68+
69+
class TestMap
70+
{
71+
72+
/**
73+
* @template TKey
74+
* @template TValue
75+
*
76+
* @param iterable<TKey, TValue> $iterator
77+
* @param callable(TValue, TKey):(TValue|Map<TKey, TValue>) $callback
78+
*
79+
* @return iterable<TKey, TValue>
80+
*/
81+
function iterator_map(iterable $iterator, callable $callback): iterable
82+
{
83+
foreach ($iterator as $key => $value) {
84+
$result = $callback($value, $key);
85+
if ($result instanceof Map) {
86+
yield $result->key() => $result->value();
87+
continue;
88+
}
89+
yield $key => $result;
90+
}
91+
}
92+
93+
}

0 commit comments

Comments
 (0)