Skip to content

Trait constructors on scala.js #7377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ class LinkScala2Impls extends MiniPhase with IdentityDenotTransformer { thisPhas
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 Apply(sel @ Select(Super(a, b), _), args)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part should be improved but basically tells to do the transform for constructors even on scala.js

if sel.symbol.owner.is(Scala2x) && currentClass.mixins.contains(sel.symbol.owner) && sel.symbol.isConstructor =>
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
}
Expand All @@ -88,8 +94,13 @@ class LinkScala2Impls extends MiniPhase with IdentityDenotTransformer { thisPhas
val implName = ImplMethName(meth.name.asTermName)
val cls = meth.owner
if (cls.isAllOf(Scala2xTrait))
if (meth.isConstructor)
if (meth.isConstructor) {
if (ctx.settings.scalajs.value) {
// Is this the static call?
cls.info.decl(nme.TRAIT_CONSTRUCTOR).symbol
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is incorrect but haven't been able to figure out the correct call, any suggestions?

} else
cls.info.decl(nme.TRAIT_CONSTRUCTOR).symbol
}
else
cls.info.decl(implName)
.suchThat(c => FullParameterization.memberSignature(c.info) == meth.signature)
Expand Down
1 change: 1 addition & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ object Build {
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/junit" ** (("*.scala": FileFilter) -- "JUnitAnnotationsParamTest.scala")).get
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/niobuffer" ** (("*.scala": FileFilter) -- "ByteBufferTest.scala")).get
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/niocharset" ** (("*.scala": FileFilter) -- "BaseCharsetTest.scala" -- "Latin1Test.scala" -- "USASCIITest.scala" -- "UTF16Test.scala" -- "UTF8Test.scala")).get
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/scalalib/RangesTest.scala").get
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/scalalib" ** (("*.scala": FileFilter) -- "ArrayBuilderTest.scala" -- "ClassTagTest.scala" -- "EnumerationTest.scala" -- "RangesTest.scala" -- "SymbolTest.scala")).get
++ (dir / "shared/src/test/require-sam" ** (("*.scala": FileFilter) -- "SAMTest.scala")).get
)
Expand Down
13 changes: 13 additions & 0 deletions sandbox/scalajs/src/Integral.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package hello

// Minimal reproduction
object Integral {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using this for testing but it probably should be removed before merging

def main(args: Array[String]): Unit = {
trait A[T] extends Ordering[T]
case class B[T](v: T) extends A[T] {
def compare(x: T, y: T): Int = 0
}

B(0)
}
}