Skip to content

NoClassDefFoundError: scala/$repeated$ when using varargs and default arguments #4073

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

Closed
max-leuthaeuser opened this issue Mar 5, 2018 · 1 comment

Comments

@max-leuthaeuser
Copy link

With Scala 2.12.4 the following works:

class DynImpl extends Dynamic {
  def applyDynamic(name: String)(args: Any*)(implicit implicitArg: String = "foo"): String =
    s"method '$name' called with arguments ${args.mkString("'", "', '", "'")} and implicit argument '$implicitArg'"
}

object Main {
  def main(args:Array[String]): Unit = {
    val d = new DynImpl

    println(d.some())

    println(d.ints(1, 2, 3))

    println(d.strings("a", "b", "c"))
  }
}

The exact same code with Dotty (0.6 or latest) fails with:

sbt: [error] (run-main-d5) java.lang.NoClassDefFoundError: scala/$repeated$
sbt: java.lang.NoClassDefFoundError: scala/$repeated$
	at Main$.main(main.scala:10)
	at Main.main(main.scala)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
Caused by: java.lang.ClassNotFoundException: scala.$repeated$
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at Main$.main(main.scala:10)
	at Main.main(main.scala)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
@nicolasstucki
Copy link
Contributor

Minimized:

object Main {
  def main(args:Array[String]): Unit = println(foo(1, 2, 3))
  def foo(args: Any*)(arg: String = "foo"): String = arg
}

The code that reaches the backend is:

package <empty> {
  @scala.annotation.internal.SourceFile("Foo.scala") final module class Main$
     extends
   Object { 
    def <init>(): Unit = 
      {
        super()
        ()
      }
    def main(args: String[]): Unit = 
      println(
        {
          val args$1: <repeated> = 
            Predef.genericWrapArray(
              [scala.Int.box(1),scala.Int.box(2),scala.Int.box(3) : Object]
            ).asInstanceOf[<repeated>]: <repeated>
          {
            closure(args$1 | this.main$$anonfun$1)
          }
        }
      )
    def foo(args: scala.collection.Seq, arg: String): String = arg
    def foo$default$2(args: scala.collection.Seq): String = "foo"
    private def main$$anonfun$1(args$1$1: <repeated>, arg: String): String = 
      Main.foo(args$1$1, arg)
  }
  final lazy module val Main: Main$ = new Main$()
}

There are two issues with this code

  • The type of the lifted args$1 is <repeated>
  • The application foo(1, 2, 3) becomes a closure even if arg has a default value.

@nicolasstucki nicolasstucki changed the title NoClassDefFoundError: scala/$repeated$ when using the Dynamic Trait with implicit Argument NoClassDefFoundError: scala/$repeated$ when using varargs and default arguments Mar 5, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 8, 2018
@nicolasstucki nicolasstucki self-assigned this Mar 8, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 8, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 9, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 9, 2018
nicolasstucki added a commit that referenced this issue Mar 13, 2018
Fix #4073: erase <repeted> type from lifted val for a vararg
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

2 participants