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

Unified Diff: frog/minfrog

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
Index: frog/minfrog
diff --git a/frog/minfrog b/frog/minfrog
index 62b87f849a733d56aec6e897e0a4c768d2b0a6cb..2d5d1d301a841e4c291553ff826ce6737f79591c 100755
--- a/frog/minfrog
+++ b/frog/minfrog
@@ -5599,6 +5599,9 @@ MethodMember.prototype._invokeConstConstructor = function(node, code, target, ar
var x = assign.x;
var fname = x.get$name().get$name();
var val = this.generator.visitValue(assign.y);
+ if (!val.get$isConst()) {
+ $globals.world.error('invalid non-const initializer in const constructor', assign.y.span);
+ }
fields.$setindex(fname, val);
}
}
@@ -5607,8 +5610,13 @@ MethodMember.prototype._invokeConstConstructor = function(node, code, target, ar
var $$list = this.declaringType.get$members().getValues();
for (var $$i = this.declaringType.get$members().getValues().iterator$0(); $$i.hasNext$0(); ) {
var f = $$i.next$0();
- if ((f instanceof FieldMember) && !f.get$isStatic() && f.get$value() != null && !fields.containsKey(f.get$name())) {
- fields.$setindex(f.get$name(), f.computeValue$0());
+ if ((f instanceof FieldMember) && !f.get$isStatic() && !fields.containsKey(f.get$name())) {
+ if (!f.get$isFinal()) {
+ $globals.world.error(('const class "' + this.declaringType.name + '" has non-final ') + ('field "' + f.get$name() + '"'), f.get$span());
+ }
+ if (f.get$value() != null) {
+ fields.$setindex(f.get$name(), f.computeValue$0());
+ }
}
}
return $globals.world.gen.globalForConst(ConstObjectValue.ConstObjectValue$factory(target.get$type(), fields, code, node.span), args.values);

Powered by Google App Engine
This is Rietveld 408576698