Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

applyDynamic does not support passing a vararg parameter #9308

Open
scabug opened this issue May 12, 2015 · 8 comments
Open

applyDynamic does not support passing a vararg parameter #9308

scabug opened this issue May 12, 2015 · 8 comments

Comments

@scabug
Copy link

scabug commented May 12, 2015

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

scala-js/scala-js#1656 (comment)

@scabug
Copy link
Author

scabug commented May 12, 2015

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

@scabug
Copy link
Author

scabug commented Mar 17, 2017

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

@DavidPerezIngeniero
Copy link

Any workaround?

@SethTisue SethTisue added this to the Backlog milestone Mar 20, 2018
@SethTisue
Copy link
Member

SethTisue commented Mar 20, 2018

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

@OndrejSpanel
Copy link
Member

OndrejSpanel commented Mar 30, 2022

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

@julienrf
Copy link

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

@OndrejSpanel
Copy link
Member

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
Copy link
Member

OndrejSpanel commented Apr 2, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants