Skip to content

No error in case of iterating over void in for-in loops #57078

@sgrekhov

Description

@sgrekhov

In the language specification we have:

It is a compile-time error for a for-in statement
to have an iterator expression of type T such that Iterator< void > is the most
specific instantiation of Iterator that is a superinterface of T, unless the iteration variable has type void. It is a compile-time error for an asynchronous
for-in statement to have a stream expression of type T such that Stream< void >
is the most specific instantiation of Stream that is a superinterface of T, unless
the iteration variable has type void.

But the code below doen't have expected errors nor in the analyzer nor in the CFE.

void main() async {
  List<void> list = <void>[1, 2, 3];
  for (Object? i in list) {
//                  ^^^^
// [analyzer] unspecified
// [cfe] unspecified
  }
  for (dynamic i in list) {
//                  ^^^^
// [analyzer] unspecified
// [cfe] unspecified
  }

  Stream<void> stream = Stream<void>.fromIterable([1, 2, 3]);
  await for (Object? i in stream) {
//                        ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
  }
  await for (dynamic i in stream) {
//                        ^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
  }
}

Metadata

Metadata

Labels

cfe-dysfunctionalitiesIssues for the CFE not behaving as intendedlegacy-area-front-endLegacy: Use area-dart-model instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions