From ad9c6423a33add823f8b0ff4142d1b14c5839740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Thu, 29 Oct 2020 11:41:50 +0100 Subject: [PATCH] Scala.js: Handle private inner JS classes. Sometimes, a private inner JS class doesn't need an outer pointer at all, and hence its constructor doesn't take any argument. This corner case needs to be handled in the codegen for `createInnerJSClass`. --- compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala | 9 ++++++++- project/Build.scala | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala index 281591b7d16a..a75716cd2ab2 100644 --- a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala +++ b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala @@ -3384,8 +3384,15 @@ class JSCodeGen()(using genCtx: Context) { } else { val captureValues = { if (code == CREATE_INNER_JS_CLASS) { + /* Private inner classes that do not actually access their outer + * pointer do not receive an outer argument. We therefore count + * the number of constructors that have non-empty param list to + * know how many times we need to pass `this`. + */ + val requiredThisParams = + classSym.info.decls.lookupAll(nme.CONSTRUCTOR).count(_.info.paramInfoss.head.nonEmpty) val outer = genThis() - List.fill(classSym.info.decls.lookupAll(nme.CONSTRUCTOR).size)(outer) + List.fill(requiredThisParams)(outer) } else { val fakeNewInstances = args(2).asInstanceOf[JavaSeqLiteral].elems fakeNewInstances.flatMap(genCaptureValuesFromFakeNewInstance(_)) diff --git a/project/Build.scala b/project/Build.scala index c1737766720b..71c018930b78 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1101,7 +1101,6 @@ object Build { ++ (dir / "shared/src/test/require-jdk7" ** "*.scala").get ++ (dir / "js/src/test/scala" ** (("*.scala": FileFilter) - -- "ExportsTest.scala" // JS exports + IR checking error -- "ObjectTest.scala" // compile errors caused by #9588 -- "StackTraceTest.scala" // would require `npm install source-map-support` -- "UnionTypeTest.scala" // requires the Scala 2 macro defined in Typechecking*.scala @@ -1118,6 +1117,7 @@ object Build { Test / testOptions += Tests.Filter { name => !Set[String]( "org.scalajs.testsuite.jsinterop.AsyncTest", // needs JS exports in PromiseMock.scala + "org.scalajs.testsuite.jsinterop.ExportsTest", // JS exports "org.scalajs.testsuite.jsinterop.JSExportStaticTest", // JS exports // Not investigated so far