-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
itype:bugstat:needs triageEvery issue needs to have an "area" and "itype" labelEvery issue needs to have an "area" and "itype" label
Description
Edited: Simplified minimized code
Compiler version
Scala 3.8.0-RC1
Output
The macro below fails compiling on ScalaJs. Compiles and run ok on JVM.
scala-cli --cli-version 1.10.1 Client.scala ClientMacro.scala
Compiles and runs ok
scala-cli --cli-version 1.10.1 Client.scala ClientMacro.scala --js
Fails compilation with error:
Error: Cannot resolve delambdafy target method $anonfun at Client.scala:20
Note, both JVM and ScalaJs compile and run on Scala 3.7.4 by adding //> using options -experimental on Client.scala
Minimized code
File Client.scala
//> using scala 3.8.0-RC1
//> using jvm temurin:25
//> using js-version 1.20.1
trait ApiRun:
def runString(): String
object ClientRunner:
val exec = Runner()
def main(args: Array[String]): Unit = println(client.runString())
inline def client: ApiRun = ${
ClientMacro.impl('exec)
}
class Runner():
def run(lambda: () => String): String = lambda()File ClientMacro.scala
object ClientMacro:
import scala.quoted.*
def impl(runnerImpl: Expr[Runner])(using Quotes): Expr[ApiRun] = implBase(runnerImpl)
private def implBase(runnerImpl: Expr[Runner])(using Quotes): Expr[ApiRun] =
import quotes.reflect.*
val parents = List(TypeTree.of[Object], TypeTree.of[ApiRun])
val cls = Symbol
.newClass(
Symbol.spliceOwner,
"ApiImpl",
parents.map(_.tpe),
cls => List(Symbol.newMethod(cls, "runString", MethodType(Nil)(_ => Nil, _ => TypeRepr.of[String]))),
selfType = None
)
val body = DefDef(cls.declaredMethods.head, _ => Some('{ ${ runnerImpl }.run(() => "ApiImpl.run") }.asTerm))
val clsDef = ClassDef(cls, parents, body = List(body))
val newCls = Apply(Select(New(TypeIdent(cls)), cls.primaryConstructor), Nil)
Block(List(clsDef), newCls).asExprOf[ApiRun]Metadata
Metadata
Assignees
Labels
itype:bugstat:needs triageEvery issue needs to have an "area" and "itype" labelEvery issue needs to have an "area" and "itype" label