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

1.7k Views Asked by At

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(","))
  }
}
2

There are 2 best solutions below

0
On BEST ANSWER

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

0
On

Issue was fixed and released in version 2020.3.20:

enter image description here