|
6 | 6 | use DateTimeImmutable; |
7 | 7 | use DateTimeInterface; |
8 | 8 | use Error; |
9 | | -use Exception; |
10 | 9 | use Iterator; |
11 | 10 | use IteratorAggregate; |
12 | 11 | use PHPStan\Php\PhpVersion; |
@@ -53,7 +52,7 @@ class UnionType implements CompoundType |
53 | 52 |
|
54 | 53 | public const EQUAL_UNION_CLASSES = [ |
55 | 54 | DateTimeInterface::class => [DateTimeImmutable::class, DateTime::class], |
56 | | - Throwable::class => [Error::class, Exception::class], |
| 55 | + Throwable::class => [Error::class, Throwable::class], |
57 | 56 | Traversable::class => [IteratorAggregate::class, Iterator::class], |
58 | 57 | ]; |
59 | 58 |
|
@@ -196,13 +195,15 @@ public function getConstantStrings(): array |
196 | 195 | public function accepts(Type $type, bool $strictTypes): AcceptsResult |
197 | 196 | { |
198 | 197 | foreach (self::EQUAL_UNION_CLASSES as $baseClass => $classes) { |
199 | | - if ($type->equals(new ObjectType($baseClass))) { |
200 | | - $union = TypeCombinator::union( |
201 | | - ...array_map(static fn (string $objectClass): Type => new ObjectType($objectClass), $classes) |
202 | | - ); |
203 | | - if ($this->accepts($union, $strictTypes)->yes()) { |
204 | | - return AcceptsResult::createYes(); |
205 | | - } |
| 198 | + if (!$type->equals(new ObjectType($baseClass))) { |
| 199 | + continue; |
| 200 | + } |
| 201 | + |
| 202 | + $union = TypeCombinator::union( |
| 203 | + ...array_map(static fn (string $objectClass): Type => new ObjectType($objectClass), $classes), |
| 204 | + ); |
| 205 | + if ($this->accepts($union, $strictTypes)->yes()) { |
| 206 | + return AcceptsResult::createYes(); |
206 | 207 | } |
207 | 208 | } |
208 | 209 |
|
|
0 commit comments