Skip to content

Commit

Permalink
Only evaluate side-effecty expression once
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmulder committed Aug 23, 2017
1 parent 1efb41a commit e4241d5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions repl/src/dotty/tools/repl/render.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import dotc.core.Symbols.Symbol
object Rendering {
/** Load the value of the symbol using reflection */
private[this] def valueOf(sym: Symbol, classLoader: ClassLoader)(implicit ctx: Context): String = {
val defn = ctx.definitions
val objectName = sym.owner.fullName.encode.toString
val resObj: Class[_] = Class.forName(objectName, true, classLoader)
val objInstance = resObj.newInstance()
objInstance
.getClass()
.getDeclaredMethods.find(_.getName == sym.name.encode.toString).get
.invoke(objInstance).toString

if (!sym.is(Flags.Method) && sym.info == defn.UnitType) "()"
else {
resObj
.getDeclaredMethods.find(_.getName == sym.name.encode.toString).get
.invoke(null).toString
}
}

def renderMethod(d: Denotation)(implicit ctx: Context): String = {
Expand Down

0 comments on commit e4241d5

Please sign in to comment.