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

Unified Diff: sdk/lib/_internal/compiler/implementation/resolution/members.dart

Issue 23533040: Check for non-final field in the face of const constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 7 years, 3 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 | sdk/lib/_internal/compiler/implementation/warnings.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/resolution/members.dart
diff --git a/sdk/lib/_internal/compiler/implementation/resolution/members.dart b/sdk/lib/_internal/compiler/implementation/resolution/members.dart
index 64593e7a1c5babdbf71b61221f43ce56faacaf3c..4aed80b6d27b2b96f673ca869eb65b22d0b04bae 100644
--- a/sdk/lib/_internal/compiler/implementation/resolution/members.dart
+++ b/sdk/lib/_internal/compiler/implementation/resolution/members.dart
@@ -668,6 +668,8 @@ class ResolverTask extends CompilerTask {
if (cls.isObject(compiler)) return;
// TODO(johnniwinther): Should this be done on the implementation element as
// well?
+ List<Element> constConstructors = <Element>[];
+ List<Element> nonFinalInstanceFields = <Element>[];
cls.forEachMember((holder, member) {
compiler.withCurrentElement(member, () {
// Perform various checks as side effect of "computing" the type.
@@ -690,12 +692,38 @@ class ResolverTask extends CompilerTask {
MessageKind.ILLEGAL_CONSTRUCTOR_MODIFIERS,
{'modifiers': mismatchedFlags});
}
+ if (member.modifiers.isConst()) {
+ constConstructors.add(member);
+ }
+ }
+ if (member.isField()) {
+ if (!member.modifiers.isStatic() &&
+ !member.modifiers.isFinal()) {
+ nonFinalInstanceFields.add(member);
+ }
}
checkAbstractField(member);
checkValidOverride(member, cls.lookupSuperMember(member.name));
checkUserDefinableOperator(member);
});
});
+ if (!constConstructors.isEmpty && !nonFinalInstanceFields.isEmpty) {
+ Spannable span = constConstructors.length > 1
+ ? cls : constConstructors[0];
+ compiler.reportError(span,
+ MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS,
+ {'className': cls.name});
+ if (constConstructors.length > 1) {
+ for (Element constructor in constConstructors) {
+ compiler.reportInfo(constructor,
+ MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR);
+ }
+ }
+ for (Element field in nonFinalInstanceFields) {
+ compiler.reportInfo(field,
+ MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD);
+ }
+ }
}
void checkAbstractField(Element member) {
@@ -2723,7 +2751,6 @@ class ResolverVisitor extends MappingVisitor<Element> {
return true;
}
-
/**
* Try to resolve the constructor that is referred to by [node].
* Note: this function may return an ErroneousFunctionElement instead of
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/warnings.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698