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

Unified Diff: pkg/front_end/lib/src/fasta/kernel/kernel_enum_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
Index: pkg/front_end/lib/src/fasta/kernel/kernel_enum_builder.dart
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_enum_builder.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_enum_builder.dart
index 75e03191b7203ac88f7fefea0d9dd06d3256522a..daf330104b23416cb397acfaacfbddea94b7159b 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_enum_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_enum_builder.dart
@@ -30,8 +30,6 @@ import 'package:kernel/ast.dart'
import 'package:front_end/src/scanner/token.dart' show Token;
-import '../errors.dart' show inputError;
-
import '../modifier.dart' show constMask, finalMask, staticMask;
import '../names.dart' show indexGetName;
@@ -175,7 +173,16 @@ class KernelEnumBuilder extends SourceClassBuilder
String name = constantNamesAndOffsets[i];
int charOffset = constantNamesAndOffsets[i + 1];
if (members.containsKey(name)) {
- inputError(null, null, "Duplicated name: $name");
+ parent.addCompileTimeError(charOffset, "Duplicated name: '$name'.");
+ constantNamesAndOffsets[i] = null;
+ continue;
+ }
+ if (name == className) {
+ parent.addCompileTimeError(
+ charOffset,
+ "Name of enum constant '$name' can't be the same as the enum's "
+ "own name.");
+ constantNamesAndOffsets[i] = null;
continue;
}
KernelFieldBuilder fieldBuilder = new KernelFieldBuilder(
@@ -250,8 +257,10 @@ class KernelEnumBuilder extends SourceClassBuilder
List<Expression> values = <Expression>[];
for (int i = 0; i < constantNamesAndOffsets.length; i += 2) {
String name = constantNamesAndOffsets[i];
- KernelFieldBuilder builder = this[name];
- values.add(new StaticGet(builder.build(libraryBuilder)));
+ if (name != null) {
+ KernelFieldBuilder builder = this[name];
+ values.add(new StaticGet(builder.build(libraryBuilder)));
+ }
}
KernelFieldBuilder valuesBuilder = this["values"];
valuesBuilder.build(libraryBuilder);
@@ -281,12 +290,14 @@ class KernelEnumBuilder extends SourceClassBuilder
int index = 0;
for (int i = 0; i < constantNamesAndOffsets.length; i += 2) {
String constant = constantNamesAndOffsets[i];
- KernelFieldBuilder field = this[constant];
- field.build(libraryBuilder);
- Arguments arguments =
- new Arguments(<Expression>[new IntLiteral(index++)]);
- field.initializer =
- new ConstructorInvocation(constructor, arguments, isConst: true);
+ if (constant != null) {
+ KernelFieldBuilder field = this[constant];
+ field.build(libraryBuilder);
+ Arguments arguments =
+ new Arguments(<Expression>[new IntLiteral(index++)]);
+ field.initializer =
+ new ConstructorInvocation(constructor, arguments, isConst: true);
+ }
}
return super.build(libraryBuilder, coreLibrary);
}
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/body_builder.dart ('k') | pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698