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

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

Issue 2934713002: Various issues with duplicated names. (Closed)
Patch Set: Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/kernel/kernel_enum_builder.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/fasta/kernel/body_builder.dart
diff --git a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
index 8afec2ee626ba9b20be7266195d54e6293e688f2..3fe1858773b1fd0b26d8a42c9eb85be055af76c3 100644
--- a/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/body_builder.dart
@@ -618,6 +618,33 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
arguments.getRange(0, firstNamedArgumentIndex));
List<NamedExpression> named = new List<NamedExpression>.from(
arguments.getRange(firstNamedArgumentIndex, arguments.length));
+ if (named.length == 2) {
+ if (named[0].name == named[1].name) {
+ named = <NamedExpression>[
+ new NamedExpression(
+ named[1].name,
+ buildCompileTimeError(
+ "Duplicated named argument '${named[1].name}'.",
+ named[1].fileOffset))
+ ];
+ }
+ } else if (named.length > 2) {
+ Map<String, NamedExpression> seenNames = <String, NamedExpression>{};
+ bool hasProblem = false;
+ for (NamedExpression expression in named) {
+ if (seenNames.containsKey(expression.name)) {
+ hasProblem = true;
+ seenNames[expression.name].value = buildCompileTimeError(
+ "Duplicated named argument '${expression.name}'.",
+ expression.fileOffset);
+ } else {
+ seenNames[expression.name] = expression;
+ }
+ }
+ if (hasProblem) {
+ named = new List<NamedExpression>.from(seenNames.values);
+ }
+ }
push(new KernelArguments(positional, named: named)
..fileOffset = beginToken.charOffset);
} else {
@@ -2216,6 +2243,10 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
name.name, functionNestingLevel,
isFinal: true, isLocalFunction: true)
..fileOffset = offsetForToken(name.token);
+ if (scope.local[variable.name] != null) {
+ addCompileTimeError(offsetForToken(name.token),
+ "'${variable.name}' already declared in this scope.");
+ }
push(new KernelFunctionDeclaration(
variable,
// The function node is created later.
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/kernel/kernel_enum_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698