Skip to content

Commit c9f4222

Browse files
committed
Fix mixin codegen for an object Foo extends js.Any inside a trait.
The `New` is not enough for an `object class Foo$` that is an inner JS object. It needs the correct wrapping generated by `ExplicitJSClasses`. That wrapping exists in the `lazy def` defined in the trait, but cannot be reproduced in the implementing class. In general, we need full paths to do that, which are long gone. When extending a Scala 3-defined trait, we can actually generate a call to the `lazy def`. Although it was never called before (and still is never called for non-JS objects), it was always generated by the Scala 3 compilers. Scala 2, however, does not emit those `lazy def`s. Since I don't see a way out (yet), we report an "Implementation restriction" error in that case.
1 parent 7dc3d24 commit c9f4222

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

compiler/src/dotty/tools/dotc/transform/Mixin.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import NameKinds.*
1818
import NameOps.*
1919
import ast.Trees.*
2020

21+
import dotty.tools.dotc.transform.sjs.JSSymUtils.isJSType
22+
2123
object Mixin {
2224
val name: String = "mixin"
2325
val description: String = "expand trait fields and trait initializers"
@@ -273,7 +275,15 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase =>
273275
else if (getter.is(Lazy, butNot = Module))
274276
transformFollowing(superRef(getter).appliedToNone)
275277
else if (getter.is(Module))
276-
New(getter.info.resultType, List(This(cls)))
278+
if ctx.settings.scalajs.value && getter.moduleClass.isJSType then
279+
if getter.is(Scala2x) then
280+
report.error(
281+
em"""Implementation restriction: cannot extend the Scala 2 trait $mixin
282+
|containing the object $getter that extends js.Any""",
283+
cls.srcPos)
284+
transformFollowing(superRef(getter).appliedToNone)
285+
else
286+
New(getter.info.resultType, List(This(cls)))
277287
else
278288
Underscore(getter.info.resultType)
279289
// transformFollowing call is needed to make memoize & lazy vals run

0 commit comments

Comments
 (0)