Skip to content

Commit

Permalink
try fix again
Browse files Browse the repository at this point in the history
  • Loading branch information
molikto committed Jan 11, 2020
1 parent a0e3a9d commit e950981
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 36 deletions.
35 changes: 23 additions & 12 deletions compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1397,19 +1397,30 @@ class JSCodeGen()(implicit ctx: Context) {
} else /*if (isScalaJSDefinedJSClass(currentClassSym)) {
genJSSuperCall(tree, isStat)
} else*/ {
val superCall = genApplyMethodStatically(
genThis()(sup.span), sym, genActualArgs(sym, args))

// Initialize the module instance just after the super constructor call.
if (isStaticModule(currentClassSym) && !isModuleInitialized &&
currentMethodSym.get.isClassConstructor) {
isModuleInitialized = true
val className = encodeClassName(currentClassSym)
val thisType = jstpe.ClassType(className)
val initModule = js.StoreModule(className, js.This()(thisType))
js.Block(superCall, initModule)
if (sym.owner.isAllOf(Scala2x | Trait) && sym.isConstructor) {
// calling genApplyMethodStatically will genereate a method with one argumetn for `this`, so we do it manually a zero-argument method
assert(args.size == 0)
val sym0 = sym.owner.info.decl(nme.TRAIT_CONSTRUCTOR).symbol.name.mangledString
val methodIdent = js.MethodIdent(MethodName(SimpleMethodName(sym0), List.empty, jstpe.VoidRef, false))
js.ApplyStatically(
js.ApplyFlags.empty, genThis()(sup.span),
encodeClassName(sym.owner),
methodIdent,
List.empty)(toIRType(defn.UnitType))
} else {
superCall
val superCall = genApplyMethodStatically(
genThis()(sup.span), sym, genActualArgs(sym, args))
// Initialize the module instance just after the super constructor call.
if (isStaticModule(currentClassSym) && !isModuleInitialized &&
currentMethodSym.get.isClassConstructor) {
isModuleInitialized = true
val className = encodeClassName(currentClassSym)
val thisType = jstpe.ClassType(className)
val initModule = js.StoreModule(className, js.This()(thisType))
js.Block(superCall, initModule)
} else {
superCall
}
}
}
}
Expand Down
43 changes: 19 additions & 24 deletions compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,34 +73,29 @@ class LinkScala2Impls extends MiniPhase with IdentityDenotTransformer { thisPhas
override def transformApply(app: Apply)(implicit ctx: Context): Tree = {
def currentClass = ctx.owner.enclosingClass.asClass
app match {
case Apply(sel @ Select(sup@Super(_, _), _), args)
if sel.symbol.owner.is(Scala2x) && currentClass.mixins.contains(sel.symbol.owner)=>
val meth = sel.symbol
val cls = meth.owner
val implName = ImplMethName(meth.name.asTermName)
val sjs = ctx.settings.scalajs.value
// The 2.12 implementation method of a super call or implementation class target
if (cls.isAllOf(Scala2xTrait))
inline def returnImpl(impl: Symbol) =
if (impl.exists) Apply(ref(impl), This(currentClass) :: args).withSpan(app.span)
else app // could have been an abstract method in a trait linked to from a super constructor
if (meth.isConstructor)
if (sjs)
Apply(This(cls.asInstanceOf[ClassSymbol]).select(nme.TRAIT_CONSTRUCTOR), args).withSpan(app.span)
else
returnImpl(cls.info.decl(nme.TRAIT_CONSTRUCTOR).symbol)
else
if (sjs)
app
else
returnImpl(cls.info.decl(implName)
.suchThat(c => FullParameterization.memberSignature(c.info) == meth.signature)
.symbol)
else throw new AssertionError(i"no impl method for $meth")
case Apply(sel @ Select(Super(_, _), _), args)
if sel.symbol.owner.is(Scala2x) && currentClass.mixins.contains(sel.symbol.owner) && !ctx.settings.scalajs.value =>
val impl = implMethod(sel.symbol)
if (impl.exists) Apply(ref(impl), This(currentClass) :: args).withSpan(app.span)
else app // could have been an abstract method in a trait linked to from a super constructor
case _ =>
app
}
}

/** The 2.12 implementation method of a super call or implementation class target */
private def implMethod(meth: Symbol)(implicit ctx: Context): Symbol = {
val implName = ImplMethName(meth.name.asTermName)
val cls = meth.owner
if (cls.isAllOf(Scala2xTrait))
if (meth.isConstructor)
cls.info.decl(nme.TRAIT_CONSTRUCTOR).symbol
else
cls.info.decl(implName)
.suchThat(c => FullParameterization.memberSignature(c.info) == meth.signature)
.symbol
else throw new AssertionError(i"no impl method for $meth")
}

private val Scala2xTrait = Scala2x | Trait
}

0 comments on commit e950981

Please sign in to comment.