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

Unified Diff: frog/gen.dart

Issue 8589016: Add implicit super() call (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month 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 | « frog/frogsh ('k') | frog/member.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/gen.dart
diff --git a/frog/gen.dart b/frog/gen.dart
index 19028c73130d6d6bcf0d3f052e643359855e784f..3b30f07a0fe4b4c996d08cc4aee8837b0d7ba538 100644
--- a/frog/gen.dart
+++ b/frog/gen.dart
@@ -832,13 +832,13 @@ class MethodGenerator implements TreeVisitor {
method.definition.span);
}
+ var initializerCall = null;
+ final declaredInitializers = method.definition.initializers;
if (initializers != null) {
for (var i in initializers) {
writer.writeln(i);
}
- final declaredInitializers = method.definition.initializers;
if (declaredInitializers != null) {
- var initializerCall = null;
for (var init in declaredInitializers) {
// TODO(jimhug): Lot's of correctness to verify here.
if (init is CallExpression) {
@@ -873,37 +873,44 @@ class MethodGenerator implements TreeVisitor {
world.error('invalid initializer', init.span);
}
}
+ }
+ writer.comment('// Initializers done');
+ }
- if (initializerCall != null) {
- var target = _writeInitializerCall(initializerCall);
- if (!target.isSuper) {
- // when calling another constructor on the same class
- // no other initialization is allowed
- if (initializers.length > 0) {
- for (var p in method.parameters) {
- if (p.isInitializer) {
- world.error(
- 'no initialization allowed on redirecting constructors',
- p.definition.span);
- break;
- }
- }
- }
- if (declaredInitializers.length > 1) {
- var init = declaredInitializers[0] == initializerCall
- ? declaredInitializers[1] : declaredInitializers[0];
+ if (method.isConstructor && initializerCall == null) {
+ var parentType = method.declaringType.parent;
+ if (parentType != null && !parentType.isObject) {
+ // TODO(jmesserly): we could omit this if all supertypes are using
+ // default constructors.
+ initializerCall = new CallExpression(
+ new SuperExpression(method.span), [], method.span);
+ }
+ }
+
+ if (initializerCall != null) {
+ var target = _writeInitializerCall(initializerCall);
+ if (!target.isSuper) {
+ // when calling another constructor on the same class
+ // no other initialization is allowed
+ if (initializers.length > 0) {
+ for (var p in method.parameters) {
+ if (p.isInitializer) {
world.error(
'no initialization allowed on redirecting constructors',
- init.span);
+ p.definition.span);
+ break;
}
- initializedFields = null;
}
- // TODO(sigmund): check for initialization cycles
- } else {
- // TODO(jimhug): Is it an error not to have an initializerCall?
}
+ if (declaredInitializers != null && declaredInitializers.length > 1) {
+ var init = declaredInitializers[0] == initializerCall
+ ? declaredInitializers[1] : declaredInitializers[0];
+ world.error(
+ 'no initialization allowed on redirecting constructors',
+ init.span);
+ }
+ initializedFields = null;
}
- writer.comment('// Initializers done');
}
// check that initialization was correct
« no previous file with comments | « frog/frogsh ('k') | frog/member.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698