@@ -2472,20 +2472,34 @@ class JSCodeGen()(using genCtx: Context) {
24722472 box(call, sym.info.finalResultType)
24732473 }
24742474
2475- val closure = js.Closure (arrow = true , formalCaptures, formalParams, genBody, actualCaptures)
2476- report.debuglog(closure.toString)
2477-
24782475 val funInterfaceSym = functionalInterface.tpe.widenDealias.typeSymbol
2479- if (jsdefn.isJSFunctionClass(funInterfaceSym)) {
2480- closure
2476+
2477+ if (jsdefn.isJSThisFunctionClass(funInterfaceSym)) {
2478+ val thisParam :: otherParams = formalParams
2479+ js.Closure (
2480+ arrow = false ,
2481+ formalCaptures,
2482+ otherParams,
2483+ js.Block (
2484+ js.VarDef (thisParam.name, thisParam.originalName,
2485+ thisParam.ptpe, mutable = false ,
2486+ js.This ()(thisParam.ptpe)(thisParam.pos))(thisParam.pos),
2487+ genBody),
2488+ actualCaptures)
24812489 } else {
2482- assert(! funInterfaceSym.exists || defn.isFunctionClass(funInterfaceSym),
2483- s " Invalid functional interface $funInterfaceSym reached the back-end " )
2484- val formalCount = formalParams.size
2485- val cls = ClassName (" scala.scalajs.runtime.AnonFunction" + formalCount)
2486- val ctorName = MethodName .constructor(
2487- jstpe.ClassRef (ClassName (" scala.scalajs.js.Function" + formalCount)) :: Nil )
2488- js.New (cls, js.MethodIdent (ctorName), List (closure))
2490+ val closure = js.Closure (arrow = true , formalCaptures, formalParams, genBody, actualCaptures)
2491+
2492+ if (jsdefn.isJSFunctionClass(funInterfaceSym)) {
2493+ closure
2494+ } else {
2495+ assert(! funInterfaceSym.exists || defn.isFunctionClass(funInterfaceSym),
2496+ s " Invalid functional interface $funInterfaceSym reached the back-end " )
2497+ val formalCount = formalParams.size
2498+ val cls = ClassName (" scala.scalajs.runtime.AnonFunction" + formalCount)
2499+ val ctorName = MethodName .constructor(
2500+ jstpe.ClassRef (ClassName (" scala.scalajs.js.Function" + formalCount)) :: Nil )
2501+ js.New (cls, js.MethodIdent (ctorName), List (closure))
2502+ }
24892503 }
24902504 }
24912505
0 commit comments