|
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 |
|
@@ -204,13 +203,15 @@ public function accepts(Type $type, bool $strictTypes): TrinaryLogic |
204 | 203 | public function acceptsWithReason(Type $type, bool $strictTypes): AcceptsResult |
205 | 204 | { |
206 | 205 | foreach (self::EQUAL_UNION_CLASSES as $baseClass => $classes) { |
207 | | - if ($type->equals(new ObjectType($baseClass))) { |
208 | | - $union = TypeCombinator::union( |
209 | | - ...array_map(static fn (string $objectClass): Type => new ObjectType($objectClass), $classes) |
210 | | - ); |
211 | | - if ($this->accepts($union, $strictTypes)->yes()) { |
212 | | - return AcceptsResult::createYes(); |
213 | | - } |
| 206 | + if (!$type->equals(new ObjectType($baseClass))) { |
| 207 | + continue; |
| 208 | + } |
| 209 | + |
| 210 | + $union = TypeCombinator::union( |
| 211 | + ...array_map(static fn (string $objectClass): Type => new ObjectType($objectClass), $classes), |
| 212 | + ); |
| 213 | + if ($this->accepts($union, $strictTypes)->yes()) { |
| 214 | + return AcceptsResult::createYes(); |
214 | 215 | } |
215 | 216 | } |
216 | 217 |
|
|
0 commit comments