bug icon indicating copy to clipboard operation
bug copied to clipboard

applyDynamic does not support passing a vararg parameter

Open scabug opened this issue 10 years ago • 8 comments

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

scabug avatar May 12 '15 13:05 scabug

Imported From: https://issues.scala-lang.org/browse/SI-9308?orig=1 Reporter: Yoel R GARCIA DIAZ (yoeluk)

scabug avatar May 12 '15 13:05 scabug

Anton Kulaga (antonkulaga) said: Yes, please, fix it. It is super annoying!

scabug avatar Mar 17 '17 10:03 scabug

Any workaround?

DavidPerezIngeniero avatar Mar 20 '18 09:03 DavidPerezIngeniero

does anyone know if there is some real difficulty adding this, or whether the omission was just an oversight?

SethTisue avatar Mar 20 '18 12:03 SethTisue

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

OndrejSpanel avatar Mar 30 '22 20:03 OndrejSpanel

Hey Ondrej, why do you nice varargs splice here? It seems js.Dynamic.literal(s) works?

julienrf avatar Mar 31 '22 08:03 julienrf

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.)

OndrejSpanel avatar Mar 31 '22 10:03 OndrejSpanel

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

OndrejSpanel avatar Apr 02 '22 13:04 OndrejSpanel