REPL has one huge semantic difference wrt is a regular compiler.
Think about what it means to be able to do this:
scala> val v1 = 23 v1: Int = 23 scala> val v1 = 42 v1: Int = 42
Could you do this in compiled Scala code? Of course not, that would be a forbidden double definition.
How does REPL do this? In fact, each line you enter is in a more nested area. The appearance of the override is the actual shading. As if you did it:
object REPL1 { val v1 = 23 object REPL2 { val v1 = 42 object REPL3 {
So how do you get companions? Place an explicit object (or other structure forming the area) around them. And remember, no empty lines. REPL will stop accepting input for a given โlineโ or โblockโ when you do this.
Randall schulz
source share