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:
parent
e1bc9c65fc
commit
681b5fb4a5
@ -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) {
|
||||
|
@ -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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user