Skip to content

Commit

Permalink
REPL print, add unevaluated comment to lazy val
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed Aug 9, 2019
1 parent c0c9df4 commit b556040
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/repl/scala/tools/nsc/interpreter/MemberHandlers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait MemberHandlers {
import global._
import naming._

import ReplStrings.{string2codeQuoted, string2code, any2stringOf, emptyStringQuoted, quotedString}
import ReplStrings.{string2codeQuoted, string2code, any2stringOf, quotedString}

private def codegenln(leadingPlus: Boolean, xs: String*): String = codegen(leadingPlus, (xs ++ Array("\n")): _*)
private def codegenln(xs: String*): String = codegenln(true, xs: _*)
Expand Down Expand Up @@ -133,7 +133,7 @@ trait MemberHandlers {
else {
// if this is a lazy val we avoid evaluating it here
val resultString =
if (mods.isLazy) emptyStringQuoted
if (mods.isLazy) quotedString(" // unevaluated")
else quotedString(" = ") + " + " + any2stringOf(path, maxStringElements)

val varOrValOrLzy =
Expand Down
6 changes: 2 additions & 4 deletions src/repl/scala/tools/nsc/interpreter/ReplStrings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,15 @@ object ReplStrings {
res.toString
}

def quotedString(str: String) =
"\"" + str + "\""
@inline final def quotedString(str: String) =
'"' + str + '"'

def string2codeQuoted(str: String) =
quotedString(string2code(str))

def any2stringOf(x: Any, maxlen: Int) =
s"_root_.scala.runtime.ScalaRunTime.replStringOf($x, $maxlen)"

val emptyStringQuoted: String = quotedString("")

// no escaped or nested quotes
private[this] val inquotes = """(['"])(.*?)\1""".r
def unquoted(s: String) = s match { case inquotes(_, w) => w ; case _ => s }
Expand Down
2 changes: 1 addition & 1 deletion test/files/run/repl-serialization.check
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ val extract: AnyRef => Unit = <function1>
val x: Int = 0
def getX(): Int
class U
lazy val y: Int
lazy val y: Int // unevaluated
evaluating z
evaluating zz
class D
Expand Down
2 changes: 1 addition & 1 deletion test/files/run/t6937.check
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ scala> class A
class A

scala> lazy val apiru = ru: ApiUniverse
lazy val apiru: scala.reflect.api.Universe
lazy val apiru: scala.reflect.api.Universe // unevaluated

scala> apiru.typeTag[A].in(cm)
val res0: reflect.runtime.universe.TypeTag[A] = TypeTag[A]
Expand Down

0 comments on commit b556040

Please sign in to comment.