diff --git a/src/Psalm/Internal/Type/TemplateContextualBoundsCollector.php b/src/Psalm/Internal/Type/TemplateContextualBoundsCollector.php index 15184e20b99..6dc4bf2d00f 100644 --- a/src/Psalm/Internal/Type/TemplateContextualBoundsCollector.php +++ b/src/Psalm/Internal/Type/TemplateContextualBoundsCollector.php @@ -193,13 +193,15 @@ private function collectGenericObject(TGenericObject $contextual_atomic, Atomic if ($return_atomic instanceof TIterable && $contextual_atomic->value === 'Generator' ) { - $this->collectAtomic(new TIterable([ + $this->collectUnion( $contextual_atomic->type_params[0] ?? Type::getMixed(), + $return_atomic->type_params[0], + ); + $this->collectUnion( $contextual_atomic->type_params[1] ?? Type::getMixed(), - ]), $return_atomic); - } - - if ($return_atomic instanceof TGenericObject + $return_atomic->type_params[1], + ); + } elseif ($return_atomic instanceof TGenericObject && $contextual_atomic->value === $return_atomic->value ) { foreach ($return_atomic->type_params as $offset => $return_type_param) {