1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #970 - improve handling of yield from statements

This commit is contained in:
Matt Brown 2018-09-04 13:29:35 -04:00
parent e1bc9c65fc
commit 681b5fb4a5
2 changed files with 23 additions and 1 deletions

View File

@ -448,7 +448,7 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P
}
}
}
} elseif ($node instanceof PhpParser\Node\Expr\Yield_) {
} elseif ($node instanceof PhpParser\Node\Expr\Yield_ || $node instanceof PhpParser\Node\Expr\YieldFrom) {
$function_like_storage = end($this->functionlike_storages);
if ($function_like_storage) {

View File

@ -323,6 +323,13 @@ class Php70Test extends TestCase
takesString($s);
}',
],
'expectNonNullableTypeWithYield' => [
'<?php
function example() : Generator {
yield from [2];
return null;
}',
],
];
}
@ -350,6 +357,21 @@ class Php70Test extends TestCase
};',
'error_message' => 'InvalidReturnStatement',
],
'expectNonNullableTypeWithNullReturn' => [
'<?php
function example() : Generator {
yield from [2];
return null;
}
function example2() : Generator {
if (rand(0, 1)) {
return example();
}
return null;
}',
'error_message' => 'NullableReturnStatement',
],
];
}
}