Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sgrekhov opened this issue Nov 13, 2024 · 2 comments
Open

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

sgrekhov opened this issue Nov 13, 2024 · 2 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. cfe-dysfunctionalities Issues for the CFE not behaving as intended type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@sgrekhov
Copy link
Contributor

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
  }
}
@dart-github-bot
Copy link
Collaborator

Summary: The issue reports that the Dart analyzer and CFE do not flag compile-time errors when iterating over a List<void> or Stream<void> using a for-in loop, despite the language specification stating that such iterations should be flagged as errors.

@dart-github-bot dart-github-bot added area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Nov 13, 2024
@sgrekhov sgrekhov changed the title No error in case of iterating ovew void in for-in loops No error in case of iterating over void in for-in loops Nov 13, 2024
@lrhn lrhn added area-front-end Use area-front-end for front end / CFE / kernel format related issues. and removed area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. labels Nov 13, 2024
@johnniwinther johnniwinther added the cfe-dysfunctionalities Issues for the CFE not behaving as intended label Nov 14, 2024
@johnniwinther
Copy link
Member

@chloestefantsova Can you take a look at this for both analyzer and CFE? Maybe we need a breaking change request since none of the tools currently report the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. cfe-dysfunctionalities Issues for the CFE not behaving as intended type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants