@@ -297,7 +297,8 @@ private function buildArrayType(
297
297
$ i = 0 ;
298
298
foreach ($ captureGroups as $ captureGroup ) {
299
299
$ isTrailingOptional = $ i >= $ countGroups - $ trailingOptionals ;
300
- $ groupValueType = $ this ->createGroupValueType ($ captureGroup , $ wasMatched , $ flags , $ isTrailingOptional , $ matchesAll );
300
+ $ isLastGroup = $ i === $ countGroups - 1 ;
301
+ $ groupValueType = $ this ->createGroupValueType ($ captureGroup , $ wasMatched , $ flags , $ isTrailingOptional , $ isLastGroup , $ matchesAll );
301
302
$ optional = $ this ->isGroupOptional ($ captureGroup , $ wasMatched , $ flags , $ isTrailingOptional , $ matchesAll );
302
303
303
304
if ($ captureGroup ->isNamed ()) {
@@ -390,7 +391,7 @@ private function isGroupOptional(RegexCapturingGroup $captureGroup, TrinaryLogic
390
391
return $ optional ;
391
392
}
392
393
393
- private function createGroupValueType (RegexCapturingGroup $ captureGroup , TrinaryLogic $ wasMatched , int $ flags , bool $ isTrailingOptional , bool $ matchesAll ): Type
394
+ private function createGroupValueType (RegexCapturingGroup $ captureGroup , TrinaryLogic $ wasMatched , int $ flags , bool $ isTrailingOptional , bool $ isLastGroup , bool $ matchesAll ): Type
394
395
{
395
396
$ groupValueType = $ this ->getValueType ($ captureGroup ->getType (), $ flags , $ matchesAll );
396
397
@@ -417,7 +418,7 @@ private function createGroupValueType(RegexCapturingGroup $captureGroup, Trinary
417
418
}
418
419
}
419
420
420
- if (!$ isTrailingOptional && !$ this ->containsUnmatchedAsNull ($ flags , $ matchesAll ) && $ captureGroup ->isOptional ()) {
421
+ if (!$ isLastGroup && !$ this ->containsUnmatchedAsNull ($ flags , $ matchesAll ) && $ captureGroup ->isOptional ()) {
421
422
$ groupValueType = TypeCombinator::union ($ groupValueType , new ConstantStringType ('' ));
422
423
}
423
424
0 commit comments