baw / scala-worksheet-plus

Atom Package for interactive Scala Worksheet
MIT License
5 stars 0 forks source link

The interpreter state needs to be reset before each run #5

Open denisftw opened 8 years ago

denisftw commented 8 years ago

I just noticed that if you create a variable in the worksheet and then delete it, the interpreter will remember it will be the source of subtle bugs.

For example, create a function that accepts an implicit argument and declare an implicit value of the same type somewhere in the worksheet:

def sayHello(implicit name: String): String = s"Hello $name"

implicit val n = "Joe"

sayHello

It will work and produce "Hello Joe", which is correct. If we then remove the word implicit in front of n and rerun the worksheet, it will continue working because it remembers that n was declared as implicit and it's still in scope. This is obviously wrong.

I fixed it on my machine by sending :reset to the Scala interpreter before the worksheet is re-evaluated. I also added an additional check in the line formatter, which fixes the red exception that Atom sometimes throws when Scala encounters an error.

Please take a look at the pull request and tell me what you think :)