@@ -419,15 +419,15 @@ class ExplicitJSClasses extends MiniPhase with InfoTransformer { thisPhase =>
419419 override def prepareForUnit (tree : Tree )(using Context ): Context =
420420 ctx.fresh.updateStore(MyState , new MyState ())
421421
422- /** Populate `nestedObject2superClassTpe ` for inner objects at the start of
422+ /** Populate `nestedObject2superTypeConstructor ` for inner objects at the start of
423423 * a `Block` or `Template`, so that they are visible even before their
424424 * definition (in their enclosing scope).
425425 */
426426 private def populateNestedObject2superClassTpe (stats : List [Tree ])(using Context ): Unit = {
427427 for (stat <- stats) {
428428 stat match {
429429 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)
431431 case _ =>
432432 }
433433 }
@@ -477,7 +477,7 @@ class ExplicitJSClasses extends MiniPhase with InfoTransformer { thisPhase =>
477477 // scala-js/scala-js#4086
478478 ref(jsdefn.Runtime_constructorOf ).appliedTo(clazzValue)
479479 } else {
480- val parentTpe = extractSuperTpeFromImpl (stat.rhs. asInstanceOf [ Template ] )
480+ val parentTpe = extractSuperTypeConstructor (stat.rhs)
481481 val superClassCtor = genJSConstructorOf(tree, parentTpe)
482482 ref(jsdefn.Runtime_createInnerJSClass ).appliedTo(clazzValue, superClassCtor)
483483 }
@@ -525,7 +525,7 @@ class ExplicitJSClasses extends MiniPhase with InfoTransformer { thisPhase =>
525525 val rhs = {
526526 val typeRef = tree.tpe
527527 val clazzValue = clsOf(typeRef)
528- val superClassCtor = genJSConstructorOf(tree, extractSuperTpeFromImpl (tree.rhs. asInstanceOf [ Template ] ))
528+ val superClassCtor = genJSConstructorOf(tree, extractSuperTypeConstructor (tree.rhs))
529529 val fakeNewInstances = {
530530 /* We need to use `reverse` because the Scope returns elements in reverse order compared to tree definitions.
531531 * 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 =>
598598 tree
599599 }
600600 } else {
601- wrapWithContextualJSClassValue(myState.nestedObject2superClassTpe (cls))(tree)
601+ wrapWithContextualJSClassValue(myState.nestedObject2superTypeConstructor (cls))(tree)
602602 }
603603 } else {
604604 tree
@@ -727,12 +727,20 @@ class ExplicitJSClasses extends MiniPhase with InfoTransformer { thisPhase =>
727727 /** Extracts the super type constructor of a `Template`, without type
728728 * parameters, so that the type is well-formed outside of the `Template`,
729729 * 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.
731741 */
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
736744}
737745
738746object ExplicitJSClasses {
@@ -741,7 +749,7 @@ object ExplicitJSClasses {
741749 val LocalJSClassValueName : UniqueNameKind = new UniqueNameKind (" $jsclass" )
742750
743751 private final class MyState {
744- val nestedObject2superClassTpe = new MutableSymbolMap [Type ]
752+ val nestedObject2superTypeConstructor = new MutableSymbolMap [Type ]
745753 val localClass2jsclassVal = new MutableSymbolMap [TermSymbol ]
746754 val notYetSelfReferencingLocalClasses = new util.HashSet [Symbol ]
747755 }
0 commit comments