scala-ide / scala-worksheet

A Scala IDE plugin for a multi-line REPL (called worksheet)
96 stars 24 forks source link

Different behavior with our without a starting 'println' line #194

Open skyluc opened 10 years ago

skyluc commented 10 years ago

The following worksheet compiles and executes:

package t2237
object CodeInWorksheet {
  println("Something, anything")                  //> Something, anything

  case class A private[A] (i: Int)
  val a1 = A(1)                                   //> a1  : t2237.CodeInWorksheet.A = A(1)
}

While the following fails, with a blinking error:

package t2237
object CodeInWorksheet {
  case class A private[A] (i: Int)
  val a1 = A(1)   // blinking error here
}

It is the result of bug in Scala (SI-8821) and a strange behavior of the worksheet.

The worksheet wraps the code inside the execute method only from the first expression. If the first (and the last) elements of the worksheet are class/object/trait definition, they stay outside of the execute.

Everything should be inside the execute method, otherwise it could some inconsistency, like class and its companion object not in the same context.