Changes in varargs methods and currying between Scala 2.9.1 and 2.10.1

Changes in varargs methods and currying between Scala 2.9.1 and 2.10.1

There seems to be scantily little information about varargs changes in 2.10.

Say you have a class and you want to define the same method twice (say you want to make apply call another named method, such as ‘get’). In 2.9.x you could just curry the original in the new definition:

object A {
  def foo(args: String*) =  { }
  def bar = foo _
}

With this you could call foo and bar with the same syntax. In 2.10 this has stopped working, however.

Scala 2.9.1

scala> :paste
// Entering paste mode (ctrl-D to finish)

object A {
  def foo(args: String*) =  { }
  def bar = foo _
}

// Exiting paste mode, now interpreting.

defined module A

scala> A.bar()

scala> A.foo()

scala> A.foo _
res1: String* => Unit = <function1>

scala> A.bar _
res2: () => String* => Unit = <function0>

Scala 2.10.1

scala> :paste
// Entering paste mode (ctrl-D to finish)

object A {
  def foo(args: String*) =  { }
  def bar = foo _
}

// Exiting paste mode, now interpreting.

defined module A

scala> A.foo()

scala> A.bar()
<console>:9: error: not enough arguments for method apply: (v1: Seq[String])Unit in trait Function1.
Unspecified value parameter v1.
              A.bar()

scala> A.bar _
res4: () => Seq[String] => Unit = <function0>

scala> A.foo _
res5: Seq[String] => Unit = <function1>

Adding a @annotation.varargs doesn’t help things, and makes the currying of A.foo worse:

scala> :paste
// Entering paste mode (ctrl-D to finish)

object A {
  @annotation.varargs def foo(args: String*) =  { }
  def bar = foo _
}

// Exiting paste mode, now interpreting.

defined module A

scala> A.foo _
<console>:9: error: ambiguous reference to overloaded definition,
both method foo in object A of type (args: Array[String])Unit
and  method foo in object A of type (args: String*)Unit
match expected type ?
              A.foo _

Mind you, this is only the lament of a somewhat lazy programmer.