|
69 | 69 | use function in_array;
|
70 | 70 | use function is_string;
|
71 | 71 | use function reset;
|
| 72 | +use function stripos; |
72 | 73 | use function strtolower;
|
73 | 74 |
|
74 | 75 | /**
|
@@ -702,15 +703,19 @@ public static function checkIteratorType(
|
702 | 703 | if ($has_valid_iterator) {
|
703 | 704 | IssueBuffer::maybeAdd(
|
704 | 705 | new PossiblyInvalidIterator(
|
705 |
| - 'Cannot iterate over ' . $invalid_iterator_types[0], |
| 706 | + stripos($invalid_iterator_types[0], 'generator<') === 0 |
| 707 | + ? 'Cannot iterate over generator with non-null send() type ' . $invalid_iterator_types[0] |
| 708 | + : 'Cannot iterate over ' . $invalid_iterator_types[0], |
706 | 709 | new CodeLocation($statements_analyzer->getSource(), $expr),
|
707 | 710 | ),
|
708 | 711 | $statements_analyzer->getSuppressedIssues(),
|
709 | 712 | );
|
710 | 713 | } else {
|
711 | 714 | IssueBuffer::maybeAdd(
|
712 | 715 | new InvalidIterator(
|
713 |
| - 'Cannot iterate over ' . $invalid_iterator_types[0], |
| 716 | + stripos($invalid_iterator_types[0], 'generator<') === 0 |
| 717 | + ? 'Cannot iterate over generator with non-null send() type ' . $invalid_iterator_types[0] |
| 718 | + : 'Cannot iterate over ' . $invalid_iterator_types[0], |
714 | 719 | new CodeLocation($statements_analyzer->getSource(), $expr),
|
715 | 720 | ),
|
716 | 721 | $statements_analyzer->getSuppressedIssues(),
|
@@ -901,7 +906,11 @@ public static function handleIterable(
|
901 | 906 | && strtolower($iterator_atomic_type->value) === 'generator'
|
902 | 907 | ) {
|
903 | 908 | $type_params = $iterator_atomic_type->type_params;
|
904 |
| - if (isset($type_params[2]) && !$type_params[2]->isNullable() && !$type_params[2]->isMixed()) { |
| 909 | + if (isset($type_params[2]) |
| 910 | + && !$type_params[2]->isNullable() |
| 911 | + && !$type_params[2]->isVoid() |
| 912 | + && !$type_params[2]->isMixed() |
| 913 | + ) { |
905 | 914 | $invalid_iterator_types[] = $iterator_atomic_type->getKey();
|
906 | 915 | } else {
|
907 | 916 | $has_valid_iterator = true;
|
|
0 commit comments