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

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

Issue 2916333002: Setup correct scope for initializers and complain about fields initialized more than once. (Closed)
Patch Set: More typos. 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_field_builder.dart
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_field_builder.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_field_builder.dart
index d7c9b7d06ff0a5439913ca3449fa149ee50880a8..e0186b4e78a6f77379f85157233f46c6714b1adf 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_field_builder.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_field_builder.dart
@@ -22,7 +22,10 @@ import 'package:front_end/src/fasta/source/source_library_builder.dart'
import 'package:front_end/src/fasta/type_inference/type_inference_listener.dart'
show TypeInferenceListener;
-import 'package:kernel/ast.dart' show DartType, Expression, Field, Name;
+import 'package:kernel/ast.dart'
+ show DartType, Expression, Field, Name, NullLiteral;
+
+import '../errors.dart' show internalError;
import 'kernel_builder.dart'
show Builder, FieldBuilder, KernelTypeBuilder, MetadataBuilder;
@@ -39,7 +42,12 @@ class KernelFieldBuilder extends FieldBuilder<Expression> {
..fileOffset = charOffset,
super(name, modifiers, compilationUnit, charOffset);
+ bool get hasInitializer => initializerToken != null;
+
void set initializer(Expression value) {
+ if (!hasInitializer && value is! NullLiteral && !isConst && !isFinal) {
+ internalError("Attempt to set initializer on field without initializer.");
+ }
field.initializer = value..parent = field;
}
@@ -55,7 +63,7 @@ class KernelFieldBuilder extends FieldBuilder<Expression> {
..hasImplicitGetter = isInstanceMember
..hasImplicitSetter = isInstanceMember && !isConst && !isFinal
..isStatic = !isInstanceMember;
- if (initializerToken != null) {
+ if (initializerToken != null && !initializerToken.isEof) {
library.loader.typeInferenceEngine.recordField(field);
}
return field;
@@ -66,7 +74,7 @@ class KernelFieldBuilder extends FieldBuilder<Expression> {
@override
void prepareInitializerInference(
SourceLibraryBuilder library, ClassBuilder currentClass) {
- if (initializerToken != null) {
+ if (initializerToken != null && !initializerToken.isEof) {
var memberScope =
currentClass == null ? library.scope : currentClass.scope;
// TODO(paulberry): Is it correct to pass library.uri into BodyBuilder, or

Powered by Google App Engine
This is Rietveld 408576698