Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(856)

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Issue 2733413002: Recover correctly from positional argument after named argument. (Closed)
Patch Set: Rename firstNamedArgumentIndex. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/co19/co19-kernel.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library fasta.body_builder; 5 library fasta.body_builder;
6 6
7 import '../parser/parser.dart' show FormalParameterType, optional; 7 import '../parser/parser.dart' show FormalParameterType, optional;
8 8
9 import '../parser/error_kind.dart' show ErrorKind; 9 import '../parser/error_kind.dart' show ErrorKind;
10 10
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 @override 458 @override
459 void endExpressionStatement(Token token) { 459 void endExpressionStatement(Token token) {
460 debugEvent("ExpressionStatement"); 460 debugEvent("ExpressionStatement");
461 push(new ExpressionStatement(popForEffect())); 461 push(new ExpressionStatement(popForEffect()));
462 } 462 }
463 463
464 @override 464 @override
465 void endArguments(int count, Token beginToken, Token endToken) { 465 void endArguments(int count, Token beginToken, Token endToken) {
466 debugEvent("Arguments"); 466 debugEvent("Arguments");
467 List arguments = popList(count) ?? <Expression>[]; 467 List arguments = popList(count) ?? <Expression>[];
468 int firstNamedArgument = arguments.length; 468 int firstNamedArgumentIndex = arguments.length;
469 for (int i = 0; i < arguments.length; i++) { 469 for (int i = 0; i < arguments.length; i++) {
470 var node = arguments[i]; 470 var node = arguments[i];
471 if (node is NamedExpression) { 471 if (node is NamedExpression) {
472 firstNamedArgument = i < firstNamedArgument ? i : firstNamedArgument; 472 firstNamedArgumentIndex =
473 i < firstNamedArgumentIndex ? i : firstNamedArgumentIndex;
473 } else { 474 } else {
474 arguments[i] = node = toValue(node); 475 arguments[i] = toValue(node);
475 if (i > firstNamedArgument) { 476 if (i > firstNamedArgumentIndex) {
476 internalError("Expected named argument: $node"); 477 arguments[i] = new NamedExpression(
478 "#$i",
479 buildCompileTimeError(
480 "Expected named argument.", arguments[i].fileOffset));
477 } 481 }
478 } 482 }
479 } 483 }
480 if (firstNamedArgument < arguments.length) { 484 if (firstNamedArgumentIndex < arguments.length) {
481 List<Expression> positional = 485 List<Expression> positional = new List<Expression>.from(
482 new List<Expression>.from(arguments.getRange(0, firstNamedArgument)); 486 arguments.getRange(0, firstNamedArgumentIndex));
483 List<NamedExpression> named = new List<NamedExpression>.from( 487 List<NamedExpression> named = new List<NamedExpression>.from(
484 arguments.getRange(firstNamedArgument, arguments.length)); 488 arguments.getRange(firstNamedArgumentIndex, arguments.length));
485 push(new Arguments(positional, named: named)); 489 push(new Arguments(positional, named: named));
486 } else { 490 } else {
487 push(new Arguments(arguments)); 491 push(new Arguments(arguments));
488 } 492 }
489 } 493 }
490 494
491 @override 495 @override
492 void handleParenthesizedExpression(BeginGroupToken token) { 496 void handleParenthesizedExpression(BeginGroupToken token) {
493 debugEvent("ParenthesizedExpression"); 497 debugEvent("ParenthesizedExpression");
494 push(popForValue()); 498 push(popForValue());
(...skipping 2204 matching lines...) Expand 10 before | Expand all | Expand 10 after
2699 } else if (node is TypeDeclarationBuilder) { 2703 } else if (node is TypeDeclarationBuilder) {
2700 return node.name; 2704 return node.name;
2701 } else if (node is PrefixBuilder) { 2705 } else if (node is PrefixBuilder) {
2702 return node.name; 2706 return node.name;
2703 } else if (node is ThisPropertyAccessor) { 2707 } else if (node is ThisPropertyAccessor) {
2704 return node.name.name; 2708 return node.name.name;
2705 } else { 2709 } else {
2706 return internalError("Unhandled: ${node.runtimeType}"); 2710 return internalError("Unhandled: ${node.runtimeType}");
2707 } 2711 }
2708 } 2712 }
OLDNEW
« no previous file with comments | « no previous file | tests/co19/co19-kernel.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698