scala-ide / scala-worksheet

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

No output for reflection expression #113

Open dotta opened 11 years ago

dotta commented 11 years ago

The following doesn't produce any output

object Reflection {
  import scala.reflect.runtime.{universe => ru }
  ru.reify{ object Test { println("Hello World!") } }
}

While I would expect it to print

res0: reflect.runtime.universe.Expr[Unit] = 
Expr[Unit]({
  object Test extends Object {
    def <init>() = {
      super.<init>();
      ()
    };
    scala.this.Predef.println("Hello World!")
  };
  ()
})

Just like in the REPL.

Here is the the instrumented code

object Reflection {;import org.scalaide.worksheet.runtime.library.WorksheetSupport._; def main(args: Array[String])=$execute{;$skip(63);
  import scala.reflect.runtime.{universe => ru }
  ru.reify{ object Test { println("Hello World!") } }
}}

Which makes it pretty clear that this is a bug in the instrumentation. What I'd expect to see is something like the following:

object Reflection {;import org.scalaide.worksheet.runtime.library.WorksheetSupport._; def main(args: Array[String])=$execute{;$skip(63)
  import scala.reflect.runtime.{universe => ru }; val res$0 =
  ru.reify{ object Test { println("Hello World!") } };System.out.println("""res0: reflect.runtime.universe.Expr[Unit] = """ + $show(res$0))}
}}
dotta commented 11 years ago

And, of course, this is now working fine. I'm puzzled.

dotta commented 11 years ago

Oh, I see! Apparently, this always breaks (consistently) on a freshly created project!

Bottom line, to reproduce the issue, create a new Scala project, then create a worksheet and paste the snippet provided in the description, and you'll see the issue.

Then, if you play around enough time with the same worksheet, you may eventually get it to a state where it starts doing the right thing. Don't ask why, I'm still trying to figure this out.