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

Crash with non-identifier expression in for (... in ...) #60358

Open
lrhn opened this issue Mar 19, 2025 · 0 comments
Open

Crash with non-identifier expression in for (... in ...) #60358

lrhn opened this issue Mar 19, 2025 · 0 comments
Assignees
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. cfe-crashes Crashes in the CFE P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@lrhn
Copy link
Member

lrhn commented Mar 19, 2025

Example:

void main() {
  var b = <int>[0];
  var ints = <dynamic>[1, 2, 3, 4];
  for (b[0] in ints) {
    print(b[0]);
  }
}

The b[0] is an assignable expression, but not an identifier.

The language grammar only allows a single identifier (or declaration) in that position, not a general expression, assignable or not.
(Could potentially allow any assignment pattern, possibly even any assignable expression, as long as it doesn't raise concerns about repeated evaluation.)

The analyzer reports "Unexpected character '['", which is correct. (It has a follow-up error if the ints array was typed as List<int>, saying that you can't assign int to List<int>, so it probably error-recovers to an assignment to b.)

The front-end crashes spectacularly in type inferece (DartPad, main branch):

compileNewDDC
Crash when compiling file:///tmp/dartpadSSKDCZ/lib/main.dart at character offset 10:
main.dart: Internal problem: Unhandled IndexSet in handleForInStatementWithoutVariable.

#0      internalProblem (package:front_end/src/base/problems.dart:50:5)
#1      unhandled (package:front_end/src/base/problems.dart:71:10)
#2      InferenceVisitorImpl.computeForInVariable (package:front_end/src/type_inference/inference_visitor.dart:1714:23)
#3      InferenceVisitorImpl._handleForInWithoutVariable (package:front_end/src/type_inference/inference_visitor.dart:1731:9)
#4      InferenceVisitorImpl.handleForInWithoutVariable (package:front_end/src/type_inference/inference_visitor.dart:1843:14)
#5      InferenceVisitorImpl.visitForInStatementWithSynthesizedVariable (package:front_end/src/type_inference/inference_visitor.dart:1880:26)
#6      ForInStatementWithSynthesizedVariable.acceptInference (package:front_end/src/kernel/internal_ast.dart:234:20)
...

Should have had a parsing error before that when the part before in was not a single identifier.

@lrhn lrhn added area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Mar 19, 2025
@johnniwinther johnniwinther added the cfe-crashes Crashes in the CFE label Mar 19, 2025
@johnniwinther johnniwinther added the P3 A lower priority bug or feature request label Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. cfe-crashes Crashes in the CFE P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants