Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala case class copy-method difference between 2.9 and 2.10

Following code compile in Scala 2.9.1:

scala> case class Foo(a: String)(val b: Int = 1)
defined class Foo

scala> val foo = Foo("some")(2)
foo: Foo = Foo(some)

scala> foo.copy("another")()
res1: Foo = Foo(another)

but in 2.10.3 we get following error:

scala> foo.copy("another")()
<console>:11: error: not enough arguments for method copy: (b: Int)Foo.
Unspecified value parameter b.
          foo.copy("another")()

Can someone explain why this is changed? And I also wanted to know if there is some clever way to do this, other than foo.copy("another")(foo.b)

like image 219
Matemaatikko Avatar asked Jan 03 '14 12:01

Matemaatikko


1 Answers

This is, unfortunately, by design: https://issues.scala-lang.org/browse/SI-6068

Auxiliary param blocks on case classes like this are generally only used for implicits. They're otherwise of limited use as they don't participate in pattern matching or (as you've seen) in copy operations.

like image 130
Kevin Wright Avatar answered Oct 01 '22 19:10

Kevin Wright