bug
bug copied to clipboard
applyDynamic does not support passing a vararg parameter
I came across this scalac bug while attempting
js.Dynamic.literal(map.toSeq: _*) // Error: applyDynamic does not support passing a vararg parameter
It turned out that any call to applyDynamic will bug out the same way
https://github.com/scala-js/scala-js/issues/1656#issuecomment-101270470
Imported From: https://issues.scala-lang.org/browse/SI-9308?orig=1 Reporter: Yoel R GARCIA DIAZ (yoeluk)
Anton Kulaga (antonkulaga) said: Yes, please, fix it. It is super annoying!
Any workaround?
does anyone know if there is some real difficulty adding this, or whether the omission was just an oversight?
I hit this issue with Scala.js running Scala 2.13.8. A simple code fails:
import scala.scalajs.js
object Values {
def apply(s: (String, js.Any)) = js.Dynamic.literal(s:_*)
}
The error is:
applyDynamic does not support passing a vararg parameter error after rewriting to scala.scalajs.js.Dynamic.literal.apply possible cause: maybe a wrong Dynamic method signature?
See https://scastie.scala-lang.org/08zsx1bBRX2yAVoCTbgd0w
Hey Ondrej, why do you nice varargs splice here? It seems js.Dynamic.literal(s) works?
I want to encapsulate js.Dynamic.literal with something which has a different implementation on JVM. (My use are three.js uniforms, but I do not think that is important here.)
I see now what you meant, I am afraid misunderstood originally. You mean js.Dynamic.literal(s) in my example works in place of js.Dynamic.literal(s:_*), not that js.Dynamic.literal(s) works instead of Values(s) (which is kind of obvious). I was not aware of that possibility.
Is it documented somewhere? How can it work? Definition of literal contains two methods,, applyDynamicNamed and applyDynamic, both expecting varargs. I did not find any mention about using js.Dynamic.literal(Seq(k -> v)) anywhere. See also https://stackoverflow.com/questions/61444019/how-to-convert-an-iterable-to-a-js-dynamic