Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why this scala code reports compilation error: recursive value x needs type

The scala code is simple:

case class X(id: Option[String] = None, username: Option[String])

object X {
  def create(x: X): X = {
    x.copy(id = Some("111"))
  }
}

class Test {

  def test() {
    val x = X.create(X(
      username = Some("Hello, world!")))

    val id = x.id.get  // !!! reports: recursive value x needs type
  }

}

Please note the line:

 val id = x.id.get

Why it reports recursive value x needs type?

If I change the variable name, as:

val dd = x.id.get

It will be OK.

PS: scala version is: 2.9.1.final

like image 397
Freewind Avatar asked Feb 05 '12 09:02

Freewind


1 Answers

Removing the default argument for id in the definition of case class X also fixes the problem which suggests that this is an instance of SI-5091.

like image 136
Miles Sabin Avatar answered Dec 31 '22 01:12

Miles Sabin