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

Dynamic calls get broken by completely unrelated uses of vararg wildcard calls #7420

Closed
scabug opened this issue Apr 25, 2013 · 5 comments
Closed
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Apr 25, 2013

Take this simple piece of code which works fine:

import scala.language.dynamics

class Foo extends Dynamic {
  def selectDynamic(s: String) {}
}

def bar {
  (new Foo).foo
  //Seq(Seq(): _*)
}

Uncommenting the line with the wildcard vararg call (no matter if it occurs before or after the otherwise working selectDynamic call) makes it fail with the following error:

/Users/szeiger/code/stest/dynamicsvarags.scala:8: error: applyDynamic does not support passing a vararg parameter
  (new Foo).foo
            ^
one error found
@scabug
Copy link
Author

scabug commented Apr 25, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7420?orig=1
Reporter: @szeiger
Affected Versions: 2.10.6, 2.11.8, 2.12.0-M5

@scabug
Copy link
Author

scabug commented Dec 27, 2013

@xeno-by said:
This is a funny consequence of how the typechecker organizes contexts. If we uncomment the provided line, then enclContext.tree, which is used to perform Dynamic desugarings, is going to be the entire block of code, and then the vararg detector that's run on enclosing tree is going to produce a false positive.

Since the entire typer context business is very brittle, I have hard time coming up with an immediate fix here. In the meanwhile, something that might work as a workaround is refactoring the code a bit, so that contexts line up correctly. E.g. writing val temp = (new Foo).foo fixes the problem.

@scabug
Copy link
Author

scabug commented Oct 29, 2014

Kazuhiro Sera (seratch) said:
FYI: our library users sometimes suffers #7420 problem.

scalikejdbc/scalikejdbc#253

@scabug
Copy link
Author

scabug commented Aug 9, 2016

Otto Chrons (ochrons) said (edited on Aug 9, 2016 8:40:47 PM UTC):
Ran into this same issue in the ScalaFiddle codebase which is using js.Dynamic. The error triggers even when the vararg call is quite far away from the dynamic usage (in my case updateDynamic)

        editor.xyz = "" // this fails, because of the :_* later
        editor.completers = js.Array(JsVal.obj(
        "getCompletions" -> { (editor: Dyn, session: Dyn, pos: Dyn, prefix: Dyn, callback: Dyn) => {
          Future.successful(Seq(("hauki", "kala"))).map {
            _.map { case (name, value) =>
              JsVal.obj(
                "value" -> value,
                "caption" -> (value + name)
              ).value
            }
          }.foreach { things => callback(null, js.Array(things: _*)) }
        }
        }
      ).value)

@scabug
Copy link
Author

scabug commented Aug 12, 2016

@paulp said:
I've also just run into this, again.

import scala.language.dynamics

class ArtifactGroup(org: String, pre: String, rev: String) extends scala.Dynamic {
  def selectDynamic(name: String) = s"$org:$pre-$name:$rev"
}

object Test {
  object scalaz extends ArtifactGroup("org.scalaz", "scalaz", "7.2.4")

  /* ok   */ def f = Seq(scalaz.core, scalaz.effect)
  /* ok   */ def g = Seq(f: _*)
  /* fail */ def h = Seq(Seq(scalaz.core, scalaz.effect): _*)

  // a.scala:12: error: applyDynamic does not support passing a vararg parameter
  //   def h = Seq(Seq(scalaz.core, scalaz.effect): _*)
  //                          ^
}

@scabug scabug added the dynamic label Apr 7, 2017
howtonotwin added a commit to howtonotwin/scala that referenced this issue Jan 6, 2018
When searching the context for the tree in question, make sure to
actually check that the tree under scrutiny matches the one we're
looking for. This means that the check for varargs won't give a false
positive if the context is too large. Fixes scala/bug#7420.

Adjust the "vararg not supported" error so it doesn't hide other errors.
@lrytz lrytz added this to the 2.12.5 milestone Mar 1, 2018
@lrytz lrytz closed this as completed Mar 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants