I'm playing around with Hack for a bit and tried to create a generator function using the yield
keyword. The documentation states that the return type of such a function should be the Continuation
interface. However, when running hh_client
on the source code example of the generator function I get the following output:
./test.php:4:3,7: Invalid yield (Typing[4110])
./test.php:3:17,28: This is an object of type Continuation
./test.php:4:3,7: It is incompatible with an object of type Generator (result of function with 'yield' in the body)
This is test.php:
<?hh
function gen(): Generator<int> {
yield 1;
yield 2;
yield 3;
}
function foo(): void {
foreach (gen() as $x) {
echo $x, "\n";
}
}
foo();
Changing the result type to Generator
gives even more warnings. What is the correct way of typing a generator function?