This is because the scala script runner starts a resident instance of the compile server (fsc
) in the background. You should be able to find a running java
process with main class scala.tools.nsc.CompileServer
after running your first script.
Note that this only happens when scala
is used to run a script, that is, a .scala
file that does not contain a single compilation unit with a main class.
Subsequent calls to scala
will use this compile server (only when used to run a script), which caches information about previous compilation runs, hence the error.
You can instruct scala not to use fsc
when running a script with:
scala -nc test.scala
You can also shut down that background instance with:
fsc -shutdown
Or reset its cache with:
fsc -reset