1

I'm using a library that makes heavy use of macros and applyDynamic. The compiler bug that prevents using varargs with applyDynamic has been causing me a lot of pain, and I'm hoping to find a workaround that allows me to pass a dynamic sequence of arguments into an applyDynamic that then invokes a macro.

I have tried to write a macro that expands the sequence or splat before invoking applyDynamic with little success, but I'm not very comfortable with Scala macros so I might have been doing something wrong.

Community
  • 1
  • 1
Leo
  • 3,036
  • 3
  • 13
  • 12

2 Answers2

4

I hit this problem while using ScalaJS on this line:

literal(seq: _*)

the workaround was simply this:

literal.applyDynamic("apply")(seq: _*)

Explanation: literal (more precisely: scala.scalajs.js.Dynamic.literal) is an object extending scala.Dynamic and the call literal(...) is desuggared to literal.apply(...), which itself should be transformed (if there were no bug) by the compiler to literal.applyDynamic("apply")(...). Well, it's a bit ugly, but one can always remove the sugar himself.

Nad78
  • 51
  • 7
0

This issue has been fixed since Scala 2.12.5

Shant Dashjian
  • 888
  • 11
  • 20
  • Are you sure? I am still hitting it with Scala.js / Scala 2.13.8 - see https://github.com/scala/bug/issues/9308 – Suma Mar 30 '22 at 20:29