Skip to content

Commit 13a0520

Browse files
authored
Fix return type of yield from (#11236)
* Fix return type of yield from * Fix
2 parents 814dfde + 12a58a9 commit 13a0520

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/Psalm/Internal/Analyzer/Statements/Expression/YieldFromAnalyzer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public static function analyze(
6767
) {
6868
$yield_from_type = $atomic_type->type_params[3];
6969
} elseif ($atomic_type instanceof TArray) {
70-
$yield_from_type = $atomic_type->type_params[1];
70+
$yield_from_type = Type::getNull();
7171
} elseif ($atomic_type instanceof TKeyedArray) {
72-
$yield_from_type = $atomic_type->getGenericValueType();
72+
$yield_from_type = Type::getNull();
7373
}
7474
} else {
7575
$yield_from_type = Type::getMixed();

tests/GeneratorTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,17 @@ function foo() : Generator {
184184
takesString($s);
185185
}',
186186
],
187+
'returnTypeArr' => [
188+
'code' => '<?php
189+
function foo() : Generator {
190+
$result = yield from [2];
191+
/** @psalm-check-type-exact $result = null */;
192+
}
193+
function foo2() : Generator {
194+
$result = yield from [];
195+
/** @psalm-check-type-exact $result = null */;
196+
}',
197+
],
187198
'expectNonNullableTypeWithYield' => [
188199
'code' => '<?php
189200
function example() : Generator {

0 commit comments

Comments
 (0)