@@ -419,15 +419,15 @@ class ExplicitJSClasses extends MiniPhase with InfoTransformer { thisPhase =>
419
419
override def prepareForUnit (tree : Tree )(using Context ): Context =
420
420
ctx.fresh.updateStore(MyState , new MyState ())
421
421
422
- /** Populate `nestedObject2superClassTpe ` for inner objects at the start of
422
+ /** Populate `nestedObject2superTypeConstructor ` for inner objects at the start of
423
423
* a `Block` or `Template`, so that they are visible even before their
424
424
* definition (in their enclosing scope).
425
425
*/
426
426
private def populateNestedObject2superClassTpe (stats : List [Tree ])(using Context ): Unit = {
427
427
for (stat <- stats) {
428
428
stat match {
429
429
case cd @ TypeDef (_, rhs) if cd.isClassDef && isInnerOrLocalJSObject(cd.symbol) =>
430
- myState.nestedObject2superClassTpe (cd.symbol) = extractSuperTpeFromImpl (rhs. asInstanceOf [ Template ] )
430
+ myState.nestedObject2superTypeConstructor (cd.symbol) = extractSuperTypeConstructor (rhs)
431
431
case _ =>
432
432
}
433
433
}
@@ -477,7 +477,7 @@ class ExplicitJSClasses extends MiniPhase with InfoTransformer { thisPhase =>
477
477
// scala-js/scala-js#4086
478
478
ref(jsdefn.Runtime_constructorOf ).appliedTo(clazzValue)
479
479
} else {
480
- val parentTpe = extractSuperTpeFromImpl (stat.rhs. asInstanceOf [ Template ] )
480
+ val parentTpe = extractSuperTypeConstructor (stat.rhs)
481
481
val superClassCtor = genJSConstructorOf(tree, parentTpe)
482
482
ref(jsdefn.Runtime_createInnerJSClass ).appliedTo(clazzValue, superClassCtor)
483
483
}
@@ -525,7 +525,7 @@ class ExplicitJSClasses extends MiniPhase with InfoTransformer { thisPhase =>
525
525
val rhs = {
526
526
val typeRef = tree.tpe
527
527
val clazzValue = clsOf(typeRef)
528
- val superClassCtor = genJSConstructorOf(tree, extractSuperTpeFromImpl (tree.rhs. asInstanceOf [ Template ] ))
528
+ val superClassCtor = genJSConstructorOf(tree, extractSuperTypeConstructor (tree.rhs))
529
529
val fakeNewInstances = {
530
530
/* We need to use `reverse` because the Scope returns elements in reverse order compared to tree definitions.
531
531
* The back-end needs the fake News to be in the same order as the corresponding tree definitions.
@@ -598,7 +598,7 @@ class ExplicitJSClasses extends MiniPhase with InfoTransformer { thisPhase =>
598
598
tree
599
599
}
600
600
} else {
601
- wrapWithContextualJSClassValue(myState.nestedObject2superClassTpe (cls))(tree)
601
+ wrapWithContextualJSClassValue(myState.nestedObject2superTypeConstructor (cls))(tree)
602
602
}
603
603
} else {
604
604
tree
@@ -727,12 +727,20 @@ class ExplicitJSClasses extends MiniPhase with InfoTransformer { thisPhase =>
727
727
/** Extracts the super type constructor of a `Template`, without type
728
728
* parameters, so that the type is well-formed outside of the `Template`,
729
729
* i.e., at the same level where the corresponding `TypeDef` is defined.
730
- * It is not necessarily *-kinded, though, which limits its applicability.
730
+ *
731
+ * For example, for the Template of a class definition like
732
+ * {{{
733
+ * class Foo[...Ts] extends pre.Parent[...Us](...args) with ... { ... }
734
+ * }}}
735
+ * we extract the type constructor `pre.Parent`, without its type
736
+ * parameters.
737
+ *
738
+ * Since the result is not necessarily *-kinded, its applicability is
739
+ * limited. It seems to be sufficient to put in a `classOf`, though, which
740
+ * is what we care about.
731
741
*/
732
- private def extractSuperTpeFromImpl (impl : Template )(using Context ): Type = {
733
- // TODO Check whether stripPoly is the right thing. Do we need a sort of rawTypeRef?
734
- impl.parents.head.tpe.stripPoly
735
- }
742
+ private def extractSuperTypeConstructor (typeDefRhs : Tree )(using Context ): Type =
743
+ typeDefRhs.asInstanceOf [Template ].parents.head.tpe.dealias.typeConstructor
736
744
}
737
745
738
746
object ExplicitJSClasses {
@@ -741,7 +749,7 @@ object ExplicitJSClasses {
741
749
val LocalJSClassValueName : UniqueNameKind = new UniqueNameKind (" $jsclass" )
742
750
743
751
private final class MyState {
744
- val nestedObject2superClassTpe = new MutableSymbolMap [Type ]
752
+ val nestedObject2superTypeConstructor = new MutableSymbolMap [Type ]
745
753
val localClass2jsclassVal = new MutableSymbolMap [TermSymbol ]
746
754
val notYetSelfReferencingLocalClasses = new util.HashSet [Symbol ]
747
755
}
0 commit comments