Skip to content

Commit 048ca9c

Browse files
committed
[fix] unionTypeDecide/RequiredValueException
1 parent bc70e4b commit 048ca9c

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# CHANGELOG
22

3+
## [v4.3.2] - 2026-05-04
4+
5+
### Fixed
6+
7+
- **Union type sequential resolution now falls through on `RequiredValueException`.**
8+
When resolving a union type (e.g. `AA|BB|CC`), `unionTypeDecide()` tries each
9+
member in declaration order and falls through on failure. Previously only
10+
`InvalidValueException`, `ValidationChainException`, and `InvalidEnumValueException`
11+
triggered fallthrough; a missing required property in one union candidate — e.g.
12+
`AA::fromArray(['b' => '123'])` when `$a` is mandatory — threw `RequiredValueException`
13+
which propagated up instead of attempting `BB` or `CC`. `RequiredValueException` is
14+
now included in the catch list. This was a regression introduced in v4.0.0-rc.1 when
15+
the catch was narrowed from `ImmutableBaseException` to a specific exception list.
16+
17+
318
## [v4.3.1] - 2026-05-04
419

520
### Fixed

src/ImmutableBase.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ private static function unionTypeDecide(array $unionType, mixed $value): mixed
668668
foreach ($unionType['types'] as $type) {
669669
try {
670670
return self::valueDecide($type, $value);
671-
} catch (InvalidValueException | ValidationChainException | InvalidEnumValueException) {
671+
} catch (InvalidValueException | ValidationChainException | InvalidEnumValueException | RequiredValueException) {
672672
continue;
673673
}
674674
}
@@ -697,12 +697,12 @@ private static function valueDecide(array $type, mixed $value): mixed
697697
$typename = $type['typename']['string'];
698698
if (!$type['isBuiltin']) {
699699
return match (true) {
700-
$value instanceof $typename => $value,
701-
(\is_string($value) || \is_int($value)) && $type['isEnum'] => self::analyzeEnum($typename, $value),
702-
\is_array($value) && is_a($typename, self::class, true) => $typename::fromArray($value),
703-
is_a($typename, SingleValueObject::class, true) && !\is_object($value) => $typename::from($value),
700+
$value instanceof $typename => $value,
701+
(\is_string($value) || \is_int($value)) && $type['isEnum'] => self::analyzeEnum($typename, $value),
702+
\is_array($value) && is_a($typename, self::class, true) => $typename::fromArray($value),
703+
is_a($typename, SingleValueObject::class, true) && !\is_object($value) => $typename::from($value),
704704
\is_string($value) && self::jsonLike($value) && is_a($typename, self::class, true) => $typename::fromJson($value),
705-
default => throw new InvalidValueException($typename, $value),
705+
default => throw new InvalidValueException($typename, $value),
706706
};
707707
}
708708
if (

0 commit comments

Comments
 (0)