@@ -566,14 +566,39 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
566
566
[genericName, typeParams, body, name]);
567
567
}
568
568
569
+ final _hasDeferredSupertype = new HashSet <ClassElement >();
570
+
571
+ bool _deferIfNeeded (DartType type, ClassElement current) {
572
+ if (type is ParameterizedType ) {
573
+ var typeArguments = type.typeArguments;
574
+ for (var typeArg in typeArguments) {
575
+ var typeElement = typeArg.element;
576
+ // FIXME(vsm): This does not track mutual recursive dependences.
577
+ if (current == typeElement || _deferIfNeeded (typeArg, current)) {
578
+ return true ;
579
+ }
580
+ }
581
+ }
582
+ return false ;
583
+ }
584
+
569
585
JS .Expression _classHeritage (ClassElement element) {
570
586
var type = element.type;
571
587
if (type.isObject) return null ;
572
588
573
589
// Assume we can load eagerly, until proven otherwise.
574
590
_loader.startTopLevel (element);
575
591
576
- JS .Expression heritage = _emitTypeName (type.superclass);
592
+ // Find the super type
593
+ JS .Expression heritage;
594
+ var supertype = type.superclass;
595
+ if (_deferIfNeeded (supertype, element)) {
596
+ // Fall back to raw type.
597
+ supertype = fillDynamicTypeArgs (supertype.element.type, rules.provider);
598
+ _hasDeferredSupertype.add (element);
599
+ }
600
+ heritage = _emitTypeName (supertype);
601
+
577
602
if (type.mixins.isNotEmpty) {
578
603
var mixins = type.mixins.map (_emitTypeName).toList ();
579
604
mixins.insert (0 , heritage);
@@ -701,6 +726,12 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
701
726
[classElem.name, _propertyName (jsPeerName)]));
702
727
}
703
728
729
+ // Deferred Superclass
730
+ if (_hasDeferredSupertype.contains (classElem)) {
731
+ body.add (js.statement ('#.prototype.__proto__ = #.prototype;' ,
732
+ [name, _emitTypeName (classElem.type.superclass)]));
733
+ }
734
+
704
735
// Interfaces
705
736
if (classElem.interfaces.isNotEmpty) {
706
737
body.add (js.statement ('#[dart.implements] = () => #;' , [
0 commit comments