0

In Scala version 2.11.8, the List class has reassignment to val errors when I view its source code in Intellij.

For example at line 278 within List.map function source code:

t.tl = nx

IntelliJ shows analyze error for that line stating that there is a reassignment to val. When I checked the source code, 't' is a variable but 'tl' is a constructor parameter which is declared as Val. And here is code snippet that IntelliJ directs me to the declaration of tl:

package scala.collection.immutable
@scala.SerialVersionUID(value = 509929039250432923)
final case class ::[B](override val head : B, private[scala] val tl : scala.collection.immutable.List[B]) extends scala.collection.immutable.List[B] with scala.Product with scala.Serializable {
  override def tail : scala.collection.immutable.List[B] = { /* compiled code */ }
  override def isEmpty : scala.Boolean = { /* compiled code */ }
}

I think that part of the code like the following example:

class Test(val x: String)

var t: Test = new Test("test")
t.x = "test2"

Similarly, IntelliJ shows the same error on assignment t.x = "test2". So, what makes the source code works even if there is a reassignment to val error.

IntelliJ version is: IntelliJ IDEA 2016.2.3 Build #IU-162.1812.17, built on August 30, 2016 JRE: 1.8.0_40-b26 amd64 JVM: Java HotSpot(TM) 64-Bit Server VM by Oracle Corporation

3
  • In general I've found IntelliJ to occasionally disagree with the Scala compiler, both on what should compile and what shouldn't. IIRC the Scala plugin reimplemented parts of the compiler rather than use the actual compiler. Commented Sep 16, 2016 at 4:14
  • It's var, not val, see github.com/scala/scala/blob/v2.11.8/src/library/scala/…. Commented Sep 16, 2016 at 6:34
  • @AlexeyRamanov Thanks for the source code link. That is correct, in the source code, it is declared as var. It is really interesting to see different code within IntelliJ even if the SerialVersionUID is same with the source code on github Commented Sep 16, 2016 at 21:49

1 Answer 1

1

Can you show the code snippet whereby you claim that tl is a val? From List source, tl is a var not a val

final case class ::[B](override val head: B, private[scala] var tl: List[B]) extends List[B] {
  override def tail : List[B] = tl
  override def isEmpty: Boolean = false
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.