Skip to content

Commit d28641c

Browse files
committedFeb 3, 2023
Fix scala#16801: Scala.js: Handle Closure's of s.r.FunctionXXL.
1 parent f5e6985 commit d28641c

11 files changed

+23
-21
lines changed
 

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -3532,13 +3532,16 @@ class JSCodeGen()(using genCtx: Context) {
35323532
val closure = js.Closure(arrow = true, formalCaptures, formalParams, restParam, genBody, actualCaptures)
35333533

35343534
if (!funInterfaceSym.exists || defn.isFunctionClass(funInterfaceSym)) {
3535-
assert(!funInterfaceSym.exists || defn.isFunctionClass(funInterfaceSym),
3536-
s"Invalid functional interface $funInterfaceSym reached the back-end")
35373535
val formalCount = formalParams.size
35383536
val cls = ClassName("scala.scalajs.runtime.AnonFunction" + formalCount)
35393537
val ctorName = MethodName.constructor(
35403538
jstpe.ClassRef(ClassName("scala.scalajs.js.Function" + formalCount)) :: Nil)
35413539
js.New(cls, js.MethodIdent(ctorName), List(closure))
3540+
} else if (funInterfaceSym.name == tpnme.FunctionXXL && funInterfaceSym.owner == defn.ScalaRuntimePackageClass) {
3541+
val cls = ClassName("scala.scalajs.runtime.AnonFunctionXXL")
3542+
val ctorName = MethodName.constructor(
3543+
jstpe.ClassRef(ClassName("scala.scalajs.js.Function1")) :: Nil)
3544+
js.New(cls, js.MethodIdent(ctorName), List(closure))
35423545
} else {
35433546
assert(funInterfaceSym.isJSType,
35443547
s"Invalid functional interface $funInterfaceSym reached the back-end")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package scala.scalajs.runtime
2+
3+
import scala.scalajs.js
4+
5+
@inline
6+
final class AnonFunctionXXL(f: js.Function1[IArray[Object], Object]) extends scala.runtime.FunctionXXL {
7+
override def apply(xs: IArray[Object]): Object = f(xs)
8+
}

‎project/MiMaFilters.scala

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ object MiMaFilters {
1717
ProblemFilters.exclude[MissingClassProblem]("scala.util.boundary$Break"),
1818
ProblemFilters.exclude[MissingClassProblem]("scala.util.boundary$Label"),
1919

20+
// Scala.js only: new runtime support class in 3.2.3; not available to users
21+
ProblemFilters.exclude[MissingClassProblem]("scala.scalajs.runtime.AnonFunctionXXL"),
22+
2023
// New experimental features in 3.3.X
2124
ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.stdLibPatches.language#experimental.clauseInterleaving"),
2225
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.stdLibPatches.language$experimental$clauseInterleaving$"),

‎tests/run/functionXXL.scala

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// scalajs: --skip --pending
2-
31
object Test {
42

53
val f = (x1: Int,

‎tests/run/i2004.scala

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// scalajs: --skip --pending
2-
31
object Test {
42
def main(args: Array[String]) = {
53

‎tests/run/implicitFunctionXXL.scala

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// scalajs: --skip --pending
2-
31
object Test {
42

53
def main(args: Array[String]): Unit = {

‎tests/run/tupled-function-andThen.scala

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// scalajs: --skip --pending
2-
31
import scala.util.TupledFunction
42

53
object Test {

‎tests/run/tupled-function-apply.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// scalajs: --skip --pending
2-
31
import scala.util.TupledFunction
42

53
object Test {
@@ -119,4 +117,4 @@ object Test {
119117
*/
120118
extension [F, Args <: Tuple, R](f: F) def apply (args: Args)(using tf: TupledFunction[F, Args => R]): R =
121119
tf.tupled(f)(args)
122-
}
120+
}

‎tests/run/tupled-function-compose.scala

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// scalajs: --skip --pending
2-
31
import scala.util.TupledFunction
42
object Test {
53
def main(args: Array[String]): Unit = {

‎tests/run/tupled-function-extension-method.scala

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// scalajs: --skip --pending
2-
31
import scala.util.TupledFunction
42
object Test {
53
def main(args: Array[String]): Unit = {
@@ -13,7 +11,7 @@ object Test {
1311
(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23, x24, x25)
1412
)
1513

16-
println(f0())
14+
portablePrintln(f0())
1715
println(f1(1))
1816
println(f2(1, 2))
1917
println(f3(1, 2, 3))
@@ -34,6 +32,10 @@ object Test {
3432

3533
}
3634

35+
def portablePrintln(x: Any): Unit =
36+
if x == () then println("()")
37+
else println(x)
38+
3739
class Expr[T](val x: T)
3840

3941
// Specialized only for arity 0 and one as auto tupling will not provide the disired effect
@@ -50,4 +52,4 @@ object Test {
5052
extension [F, Args <: Tuple, R](e: Expr[F]) def applyGiven (args: Args)(using tf: TupledFunction[F, Args ?=> R]): R =
5153
tf.tupled(e.x)(using args)
5254

53-
}
55+
}

‎tests/run/tupled-function-tupled.scala

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// scalajs: --skip --pending
2-
31
import scala.util.TupledFunction
42

53
object Test {

0 commit comments

Comments
 (0)