Skip to content

Commit d8ff9c4

Browse files
committed
SI-4829 the :load command now fails claiming a file does not exist if the command ends with a space
The :load command now tries to be smart by detecting the presence of trailing spaces that might be insignificant. On certain file systems, files with trailing whitespaces are permitted which is why we don't naievely trim the argument.
1 parent 196444e commit d8ff9c4

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/compiler/scala/tools/nsc/interpreter/ILoop.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import java.io.{ BufferedReader, FileReader }
1111
import java.util.concurrent.locks.ReentrantLock
1212
import scala.sys.process.Process
1313
import session._
14-
import scala.tools.util.{ Signallable, Javap }
14+
import scala.tools.util.{ Signallable, Javap, StringOps }
1515
import scala.annotation.tailrec
1616
import scala.collection.mutable.ListBuffer
1717
import scala.concurrent.ops
@@ -595,12 +595,13 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
595595
val f = File(filename)
596596

597597
if (f.exists) action(f)
598-
else echo("That file does not exist")
598+
else echo("\"" + filename + "\" does not appear to exist")
599599
}
600600

601601
def loadCommand(arg: String) = {
602+
val smartArg = if (File(arg).exists) arg else arg.trim
602603
var shouldReplay: Option[String] = None
603-
withFile(arg)(f => {
604+
withFile(smartArg)(f => {
604605
interpretAllFrom(f)
605606
shouldReplay = Some(":load " + arg)
606607
})
@@ -641,9 +642,10 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
641642
* if any. */
642643
def command(line: String): Result = {
643644
if (line startsWith ":") {
644-
val cmd = line.tail takeWhile (x => !x.isWhitespace)
645+
val lineNoColon = line.tail
646+
val (cmd, arg) = StringOps.splitLeft(lineNoColon, ' ').getOrElse((lineNoColon, ""))
645647
uniqueCommand(cmd) match {
646-
case Some(lc) => lc(line.tail stripPrefix cmd dropWhile (_.isWhitespace))
648+
case Some(lc) => lc(arg)
647649
case _ => ambiguousError(cmd)
648650
}
649651
}

src/compiler/scala/tools/util/StringOps.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ trait StringOps {
5454
if (idx == -1) None
5555
else Some(str take idx, str drop (if (doDropIndex) idx + 1 else idx))
5656

57+
def splitLeft(str: String, ch: Char): Option[(String, String)] = {
58+
splitAt(str, str.indexOf(' '), true)
59+
}
60+
5761
/** Returns a string meaning "n elements".
5862
*
5963
* @param n ...

0 commit comments

Comments
 (0)