summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/InterpreterLoop.scala13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/InterpreterLoop.scala b/src/compiler/scala/tools/nsc/InterpreterLoop.scala
index 944a978ec7..ff74d5177b 100644
--- a/src/compiler/scala/tools/nsc/InterpreterLoop.scala
+++ b/src/compiler/scala/tools/nsc/InterpreterLoop.scala
@@ -274,18 +274,23 @@ class InterpreterLoop(in0: Option[BufferedReader], out: PrintWriter) {
out println msg
Result(true, None)
}
+ def ambiguous(cmds: List[Command]) = "Ambiguous: did you mean " + cmds.map(":" + _.name).mkString(" or ") + "?"
// not a command
if (!line.startsWith(":"))
return Result(true, interpretStartingWith(line))
- // this lets us add commands willy-nilly and only requires enough command to disambiguate
- val (x :: args) = line.substring(1).split("""\s+""").toList
+ val tokens = line.substring(1).split("""\s+""").toList
+ if (tokens.isEmpty)
+ return withError(ambiguous(commands))
+
+ val (cmd :: args) = tokens
- commands.filter(_.name startsWith x) match {
+ // this lets us add commands willy-nilly and only requires enough command to disambiguate
+ commands.filter(_.name startsWith cmd) match {
case List(x) => x(args)
case Nil => withError("Unknown command. Type :help for help.")
- case xs => withError("Ambiguous: did you mean " + xs.map(":" + _.name).mkString(" or ") + "?")
+ case xs => withError(ambiguous(xs))
}
}