Open som-snytt opened 4 years ago
Here's another one.
scala> :pa -raw
// Entering paste mode (ctrl-D to finish)
class C
// Exiting paste mode, now interpreting.
scala> new C
val res0: C = C@5cd25b58
scala> :pa -raw
// Entering paste mode (ctrl-D to finish)
class C { def foo = 0 }
// Exiting paste mode, now interpreting.
scala> new C().foo
java.lang.NoSuchMethodError: C.foo()I
... 40 elided
fwiw I think of :paste -raw
as power-user, hackers-only, you're-on-your-own-here stuff. When I use it, I use it exactly once, at the beginning of a REPL session, and then if I need to change something, I restart the REPL.
Without :paste
and with standard :paste
things seem to define as expected, so I amended the title:
scala> class C { override def toString = "lineC" }
class C
scala> new C
val res0: C = lineC
scala> class C { override def toString = "rawC" }
class C
scala> new C
val res1: C = rawC
scala> class C { override def toString = "lineC" }
class C
scala> new C
val res0: C = lineC
scala> :paste
// Entering paste mode (ctrl-D to finish)
class C { override def toString = "pasteC" }
// Exiting paste mode, now interpreting.
class C
scala> new C
val res1: C = pasteC
reproduction steps
using Scala 2.13.2,
Also,
problem
Apparent shadowing is confusing.
An existing class on the class path is "shadowed" by a class in a line package, because REPL scope is consulted first for import candidates. That makes sense, though it might be nice to warn when a logical class name changes provenance.
A rawly pasted class is hidden by an existing class on the class path. That is probably only an issue for default empty package, so maybe keeping it off the class path would be a feature.
You can't redefine a class with raw paste.
:reset
has a hiccup as shown.Maybe what's needed is class loader management to go along with history management (collecting previously computed values).