dart-lang / sdk

The Dart SDK, including the VM, dart2js, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
9.97k stars 1.53k forks source link

analysis server crashes while parsing code #54189

Open devoncarew opened 7 months ago

devoncarew commented 7 months ago

This sample code:

void main() {
  List<int> c = [var j] = [var j] = [var j] = [12];
  print(c);
  print(j);
  final a = (final f) => 33;
  final b = (final g, final ) = 55;
  final c = (final h) async => 77;
  final d = throw 99;
}

will crash the analysis server at head. See the original bug report at https://github.com/dart-lang/dart-pad/issues/2731.

No name provided
#0      _withArgumentsPatternAssignmentDeclaresVariable (package:_fe_analyzer_shared/src/messages/codes_generated.dart:11992:21)
#1      Parser.parseVariablePattern (package:_fe_analyzer_shared/src/parser/parser_impl.dart:9768:33)
#2      Parser.parsePrimaryPattern (package:_fe_analyzer_shared/src/parser/parser_impl.dart:9576:16)
#3      Parser.parsePattern (package:_fe_analyzer_shared/src/parser/parser_impl.dart:9451:13)
#4      Parser.parseParenthesizedPatternOrRecordPattern (package:_fe_analyzer_shared/src/parser/parser_impl.dart:10002:15)
#5      Parser.parsePrimaryPattern (package:_fe_analyzer_shared/src/parser/parser_impl.dart:9605:15)
#6      Parser.parsePattern (package:_fe_analyzer_shared/src/parser/parser_impl.dart:9451:13)
#7      Parser.parsePatternAssignment (package:_fe_analyzer_shared/src/parser/parser_impl.dart:10185:13)
#8      Parser.parseExpression (package:_fe_analyzer_shared/src/parser/parser_impl.dart:5720:17)
#9      Parser.parseVariableInitializerOpt (package:_fe_analyzer_shared/src/parser/parser_impl.dart:3879:15)
#10     Parser.parseOptionallyInitializedIdentifier (package:_fe_analyzer_shared/src/parser/parser_impl.dart:8133:13)
...
devoncarew commented 7 months ago

cc @scheglov

parlough commented 7 months ago

This is due to the empty synthetic token introduced in place of the unnamed variable declaration in the record pattern.

Duplicate of https://github.com/dart-lang/sdk/issues/54178

devoncarew commented 7 months ago

Re-opening just because I think there's an additional aspect to this issue.

@scheglov - the behavior here was that the parse exception from the front end was causing the analysis server process to terminate. Even assuming we resolve https://github.com/dart-lang/sdk/issues/54178, I think it's worth hardening the analysis server so that future parse exceptions can't crash the analysis server process.

scheglov commented 4 months ago

Cannot reproduce, does not crash.

srawlins commented 4 months ago

Marking P3 for the remaining issue Devon notes above:

Even assuming we resolve https://github.com/dart-lang/sdk/issues/54178, I think it's worth hardening the analysis server so that future parse exceptions can't crash the analysis server process.