Search code examples
scalascala-collectionsintellij-scala

Scala List: why the IDEA prompts that Unused expression without side effects


The program successfully prints the 3,1,2 but I am curious about why it says that this expression is unused?

package Collection

object basics {

  def main(args: Array[String]): Unit = {
    var res = List[Int](1, 2)
    res.::=(3) // Unused expression without side effects 
    println(res.mkString(","))
  }
}

Solution

  • Perhaps some IntelliJ bug, that thinks it's just :: - pre-pend method invocation without assignment result to var. Next construction with post-fix annotation works for me well: res ::= 3

    enter image description here