diff --git a/compiler/src/dotty/tools/repl/ParseResult.scala b/compiler/src/dotty/tools/repl/ParseResult.scala index bc0305c17944..5d414ecf9b34 100644 --- a/compiler/src/dotty/tools/repl/ParseResult.scala +++ b/compiler/src/dotty/tools/repl/ParseResult.scala @@ -88,7 +88,8 @@ object Settings { /** Reset the session to the initial state from when the repl program was * started */ -case object Reset extends Command { +case class Reset(arg: String) extends Command +object Reset { val command: String = ":reset" } @@ -110,7 +111,7 @@ case object Help extends Command { |:type evaluate the type of the given expression |:doc print the documentation for the given expression |:imports show import history - |:reset reset the repl to its initial state, forgetting all session entries + |:reset [options] reset the repl to its initial state, forgetting all session entries |:settings update compiler options, if possible """.stripMargin } @@ -130,7 +131,7 @@ object ParseResult { Quit.command -> (_ => Quit), Quit.alias -> (_ => Quit), Help.command -> (_ => Help), - Reset.command -> (_ => Reset), + Reset.command -> (arg => Reset(arg)), Imports.command -> (_ => Imports), Load.command -> (arg => Load(arg)), TypeOf.command -> (arg => TypeOf(arg)), diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index 2687a2e70579..eda69b7c1ed7 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -70,11 +70,11 @@ class ReplDriver(settings: Array[String], override def sourcesRequired: Boolean = false /** Create a fresh and initialized context with IDE mode enabled */ - private def initialCtx = { + private def initialCtx(settings: List[String]) = { val rootCtx = initCtx.fresh.addMode(Mode.ReadPositions | Mode.Interactive) rootCtx.setSetting(rootCtx.settings.YcookComments, true) rootCtx.setSetting(rootCtx.settings.YreadComments, true) - setupRootCtx(settings, rootCtx) + setupRootCtx(this.settings ++ settings, rootCtx) } private def setupRootCtx(settings: Array[String], rootCtx: Context) = { @@ -99,8 +99,8 @@ class ReplDriver(settings: Array[String], * such, when the user enters `:reset` this method should be called to reset * everything properly */ - protected def resetToInitial(): Unit = { - rootCtx = initialCtx + protected def resetToInitial(settings: List[String] = Nil): Unit = { + rootCtx = initialCtx(settings) if (rootCtx.settings.outputDir.isDefault(using rootCtx)) rootCtx = rootCtx.fresh .setSetting(rootCtx.settings.outputDir, new VirtualDirectory("")) @@ -378,8 +378,8 @@ class ReplDriver(settings: Array[String], out.println(Help.text) state - case Reset => - resetToInitial() + case Reset(arg) => + resetToInitial(tokenize(arg)) initialState case Imports => diff --git a/compiler/test-resources/repl/reset-command b/compiler/test-resources/repl/reset-command new file mode 100644 index 000000000000..e47b3c45f696 --- /dev/null +++ b/compiler/test-resources/repl/reset-command @@ -0,0 +1,28 @@ +scala> def f(thread: Thread) = thread.stop() +there were 1 deprecation warning(s); re-run with -deprecation for details +def f(thread: Thread): Unit + +scala>:reset -deprecation + +scala> def f(thread: Thread) = thread.stop() +1 warning found +-- Deprecation Warning: -------------------------------------------------------- +1 | def f(thread: Thread) = thread.stop() + | ^^^^^^^^^^^ + |method stop in class Thread is deprecated since : see corresponding Javadoc for more information. +def f(thread: Thread): Unit + +scala> def resetNoArgsStillWorks = 1 +def resetNoArgsStillWorks: Int + +scala>:reset + +scala> resetNoArgsStillWorks +-- [E006] Not Found Error: ----------------------------------------------------- +1 | resetNoArgsStillWorks + | ^^^^^^^^^^^^^^^^^^^^^ + | Not found: resetNoArgsStillWorks +longer explanation available when compiling with `-explain` +1 error found + +scala>:settings "-Dfoo=bar baz"