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

Unified Diff: lib/src/codegen/js_codegen.dart

Issue 1095683005: fix super ctor logic (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: merge Created 5 years, 8 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 | « lib/runtime/dart/convert.js ('k') | test/codegen/expect/fieldtest.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/js_codegen.dart
diff --git a/lib/src/codegen/js_codegen.dart b/lib/src/codegen/js_codegen.dart
index 2edfc1b52e6fed80bd10070d34846fcbe0d164bb..8c62dfd8ec1a55815c02e4842ad8e24c690f3730 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -651,6 +651,8 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
/// `C() : super() {}`.
JS.Method _emitImplicitConstructor(
ClassDeclaration node, String name, List<FieldDeclaration> fields) {
+ assert(_hasUnnamedConstructor(node.element) == fields.isNotEmpty);
+
// If we don't have a method body, skip this.
if (fields.isEmpty) return null;
@@ -775,8 +777,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
var superCtorName = node != null ? node.constructorName : null;
var element = clazz.element;
- if (superCtorName == null &&
- (element.type.isObject || element.supertype.isObject)) {
+ if (superCtorName == null && !_shouldCallUnnamedSuperCtor(element)) {
return null;
}
@@ -787,6 +788,22 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
return js.statement('super.#(#);', [name, args])..sourceInformation = node;
}
+ bool _shouldCallUnnamedSuperCtor(ClassElement e) {
+ var supertype = e.supertype;
+ if (supertype == null) return false;
+ if (_hasUnnamedConstructor(supertype.element)) return true;
+ for (var mixin in e.mixins) {
+ if (_hasUnnamedConstructor(mixin.element)) return true;
+ }
+ return false;
+ }
+
+ bool _hasUnnamedConstructor(ClassElement e) {
+ if (e.type.isObject) return false;
+ if (!e.unnamedConstructor.isSynthetic) return true;
+ return e.fields.any((f) => !f.isStatic && !f.isSynthetic);
+ }
+
/// Initialize fields. They follow the sequence:
///
/// 1. field declaration initializer if non-const,
« no previous file with comments | « lib/runtime/dart/convert.js ('k') | test/codegen/expect/fieldtest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698