Skip to content

Commit ad9c642

Browse files
committed
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`.
1 parent 4ad3ffb commit ad9c642

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3384,8 +3384,15 @@ class JSCodeGen()(using genCtx: Context) {
33843384
} else {
33853385
val captureValues = {
33863386
if (code == CREATE_INNER_JS_CLASS) {
3387+
/* Private inner classes that do not actually access their outer
3388+
* pointer do not receive an outer argument. We therefore count
3389+
* the number of constructors that have non-empty param list to
3390+
* know how many times we need to pass `this`.
3391+
*/
3392+
val requiredThisParams =
3393+
classSym.info.decls.lookupAll(nme.CONSTRUCTOR).count(_.info.paramInfoss.head.nonEmpty)
33873394
val outer = genThis()
3388-
List.fill(classSym.info.decls.lookupAll(nme.CONSTRUCTOR).size)(outer)
3395+
List.fill(requiredThisParams)(outer)
33893396
} else {
33903397
val fakeNewInstances = args(2).asInstanceOf[JavaSeqLiteral].elems
33913398
fakeNewInstances.flatMap(genCaptureValuesFromFakeNewInstance(_))

project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,6 @@ object Build {
11011101
++ (dir / "shared/src/test/require-jdk7" ** "*.scala").get
11021102

11031103
++ (dir / "js/src/test/scala" ** (("*.scala": FileFilter)
1104-
-- "ExportsTest.scala" // JS exports + IR checking error
11051104
-- "ObjectTest.scala" // compile errors caused by #9588
11061105
-- "StackTraceTest.scala" // would require `npm install source-map-support`
11071106
-- "UnionTypeTest.scala" // requires the Scala 2 macro defined in Typechecking*.scala
@@ -1118,6 +1117,7 @@ object Build {
11181117
Test / testOptions += Tests.Filter { name =>
11191118
!Set[String](
11201119
"org.scalajs.testsuite.jsinterop.AsyncTest", // needs JS exports in PromiseMock.scala
1120+
"org.scalajs.testsuite.jsinterop.ExportsTest", // JS exports
11211121
"org.scalajs.testsuite.jsinterop.JSExportStaticTest", // JS exports
11221122

11231123
// Not investigated so far

0 commit comments

Comments
 (0)