Generator without key should allow key type `int`
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- PHP
- Stars
- 5.6k
- Forks
- 365
- Avg merge
- 1h 25m
- Merged PRs (30d)
- 6
Description
<?php
/** @return Generator<void, string> */
function generator () { yield 'x'; yield 'y'; };
// Observed: PhanTypeMismatchGeneratorYieldKey Yield statement has a key with type void but generator2() is declared to yield keys of type int in \Generator<int,string>
/** @return Generator<int, string> */
function generator2 () { yield 'x'; yield 'y'; };
php > $gen = function () { yield 'x'; };
php > foreach ($gen() as $i => $value) { var_export([$i, $value]); }
array (
0 => 0,
1 => 'x',
)
php > $gen = function () { yield 'x'; yield 'y'; };
php > foreach ($gen() as $i => $value) { var_export([$i, $value]); }
array (
0 => 0,
1 => 'x',
)array (
0 => 1,
1 => 'y',
)
php > var_export(iterator_to_array($gen()));
array (
0 => 'x',
1 => 'y',
)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the two generator examples and search the codebase for PhanTypeMismatchGeneratorYieldKey and Generator key-type validation. Check how omitted yield keys are represented when a generator is declared with an int key type; done means the second example no longer reports a mismatch while the documented key and value types remain checked.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100