summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-03-19 15:38:06 +0000
committerPaul Phillips <paulp@improving.org>2011-03-19 15:38:06 +0000
commit01203c2844e196696b8fe35acfae0ee6ede90ffa (patch)
treed9200933daa90f7851d934a4927fd6c9abe79adb
parent5bb967a3de039830dcc453bb92d3b6a0b794684f (diff)
downloadscala-01203c2844e196696b8fe35acfae0ee6ede90ffa.tar.gz
scala-01203c2844e196696b8fe35acfae0ee6ede90ffa.tar.bz2
scala-01203c2844e196696b8fe35acfae0ee6ede90ffa.zip
Added a :type command to the repl, no review.
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/ILoop.scala10
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/IMain.scala2
2 files changed, 10 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala
index 53a3448c20..3d4ff7a20b 100644
--- a/src/compiler/scala/tools/nsc/interpreter/ILoop.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/ILoop.scala
@@ -216,7 +216,8 @@ class ILoop(in0: Option[BufferedReader], protected val out: PrintWriter)
NoArgs("quit", "exit the interpreter", () => Result(false, None)),
NoArgs("replay", "reset execution and replay all previous commands", replay),
LineArg("sh", "fork a shell and run a command", shCommand),
- NoArgs("silent", "disable/enable automatic printing of results", verbosity)
+ NoArgs("silent", "disable/enable automatic printing of results", verbosity),
+ LineArg("type", "display the type of an expression without evaluating it", typeCommand)
)
}
@@ -315,6 +316,13 @@ class ILoop(in0: Option[BufferedReader], protected val out: PrintWriter)
}
}
+ private def typeCommand(line: String): Result = {
+ intp.typeOfExpression(line) match {
+ case Some(tp) => tp.toString
+ case _ => "Failed to determine type."
+ }
+ }
+
private def javapCommand(line: String): Result = {
if (line == "")
return ":javap [-lcsvp] [path1 path2 ...]"
diff --git a/src/compiler/scala/tools/nsc/interpreter/IMain.scala b/src/compiler/scala/tools/nsc/interpreter/IMain.scala
index 33dcfa59e6..527a9b153a 100644
--- a/src/compiler/scala/tools/nsc/interpreter/IMain.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/IMain.scala
@@ -993,7 +993,7 @@ class IMain(val settings: Settings, protected val out: PrintWriter) {
def asModule = safeModule(expr) map (_.tpe)
def asExpr = beSilentDuring {
val lhs = freshInternalVarName()
- interpret("val " + lhs + " = { " + expr + " } ") match {
+ interpret("lazy val " + lhs + " = { " + expr + " } ") match {
case IR.Success => typeOfExpression(lhs)
case _ => None
}