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

Unified Diff: frog/member.dart

Issue 8921009: frog: check that const constructors have potentially const initializers. Also (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years 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 | frog/minfrog » ('j') | tests/language/language.status » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/member.dart
diff --git a/frog/member.dart b/frog/member.dart
index f9f9d3a57f49bfc0a71abb464e4110c24d5c9731..d6b1b7d9a64837683e7cf7d27efc0ca4e58f1fd1 100644
--- a/frog/member.dart
+++ b/frog/member.dart
@@ -1143,6 +1143,10 @@ class MethodMember extends Member {
var x = assign.x; // DotExpression or VarExpression
var fname = x.name.name;
var val = generator.visitValue(assign.y);
+ if (!val.isConst) {
+ world.error('invalid non-const initializer in const constructor',
+ assign.y.span);
jimhug 2011/12/12 18:14:30 Could this be val.span instead? It doesn't really
Siggi Cherem (dart-lang) 2011/12/12 18:20:55 For some reason in this case they are not the same
+ }
fields[fname] = val;
}
}
@@ -1152,9 +1156,14 @@ class MethodMember extends Member {
// Add default values only if they weren't overriden in the constructor.
for (var f in declaringType.members.getValues()) {
- if (f is FieldMember && !f.isStatic && f.value != null
- && !fields.containsKey(f.name)) {
- fields[f.name] = f.computeValue();
+ if (f is FieldMember && !f.isStatic && !fields.containsKey(f.name)) {
+ if (!f.isFinal) {
+ world.error('const class "${declaringType.name}" has non-final '
+ + 'field "${f.name}"', f.span);
+ }
+ if (f.value != null) {
+ fields[f.name] = f.computeValue();
+ }
}
}
« no previous file with comments | « no previous file | frog/minfrog » ('j') | tests/language/language.status » ('J')

Powered by Google App Engine
This is Rietveld 408576698