diff --git a/compiler/src/dotty/tools/dotc/core/MacroClassLoader.scala b/compiler/src/dotty/tools/dotc/core/MacroClassLoader.scala index 896da4044b42..e56835d59c54 100644 --- a/compiler/src/dotty/tools/dotc/core/MacroClassLoader.scala +++ b/compiler/src/dotty/tools/dotc/core/MacroClassLoader.scala @@ -23,7 +23,7 @@ object MacroClassLoader { private def makeMacroClassLoader(using Context): ClassLoader = trace("new macro class loader") { val entries = ClassPath.expandPath(ctx.settings.classpath.value, expandStar=true) val urls = entries.map(cp => java.nio.file.Paths.get(cp).toUri.toURL).toArray - val out = ctx.settings.outputDir.value.jpath.toUri.toURL // to find classes in case of suspended compilation - new java.net.URLClassLoader(urls :+ out, getClass.getClassLoader) + val out = Option(ctx.settings.outputDir.value.toURL) // to find classes in case of suspended compilation + new java.net.URLClassLoader(urls ++ out.toList, getClass.getClassLoader) } } diff --git a/compiler/src/dotty/tools/repl/ParseResult.scala b/compiler/src/dotty/tools/repl/ParseResult.scala index c8d36e5c889f..9c7846cd696c 100644 --- a/compiler/src/dotty/tools/repl/ParseResult.scala +++ b/compiler/src/dotty/tools/repl/ParseResult.scala @@ -80,6 +80,11 @@ case object Imports extends Command { val command: String = ":imports" } +case class Settings(arg: String) extends Command +object Settings { + val command: String = ":settings" +} + /** Reset the session to the initial state from when the repl program was * started */ @@ -128,7 +133,8 @@ object ParseResult { Imports.command -> (_ => Imports), Load.command -> (arg => Load(arg)), TypeOf.command -> (arg => TypeOf(arg)), - DocOf.command -> (arg => DocOf(arg)) + DocOf.command -> (arg => DocOf(arg)), + Settings.command -> (arg => Settings(arg)), ) def apply(source: SourceFile)(implicit state: State): ParseResult = { diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index 40876b260394..7fd9683f86a3 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -5,6 +5,7 @@ import java.nio.charset.StandardCharsets import dotty.tools.dotc.ast.Trees._ import dotty.tools.dotc.ast.{tpd, untpd} +import dotty.tools.dotc.config.CommandLineParser.tokenize import dotty.tools.dotc.config.Properties.{javaVersion, javaVmName, simpleVersionString} import dotty.tools.dotc.core.Contexts._ import dotty.tools.dotc.core.Phases.{unfusedPhases, typerPhase} @@ -414,6 +415,20 @@ class ReplDriver(settings: Array[String], } state + case Settings(arg) => arg match + case "" => + given ctx: Context = state.context + for (s <- ctx.settings.userSetSettings(ctx.settingsState).sortBy(_.name)) + out.println(s"${s.name} = ${if s.value == "" then "\"\"" else s.value}") + state + case _ => + setup(tokenize(arg).toArray, rootCtx) match + case Some((files, ictx)) => + ictx.base.initialize()(using ictx) + rootCtx = ictx + case _ => + state.copy(context = rootCtx) + case Quit => // end of the world! state diff --git a/compiler/test-resources/repl/settings-command b/compiler/test-resources/repl/settings-command new file mode 100644 index 000000000000..a20bf23ca3a5 --- /dev/null +++ b/compiler/test-resources/repl/settings-command @@ -0,0 +1,15 @@ +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>:settings -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>