11package dotty .tools .repl
22
33import scala .language .unsafeNulls
4+
45import java .io .{File => JFile , PrintStream }
56import java .nio .charset .StandardCharsets
7+
68import dotty .tools .dotc .ast .Trees .*
79import dotty .tools .dotc .ast .{tpd , untpd }
810import dotty .tools .dotc .classpath .ClassPathFactory
@@ -20,6 +22,7 @@ import dotty.tools.dotc.core.NameOps.*
2022import dotty .tools .dotc .core .Names .Name
2123import dotty .tools .dotc .core .StdNames .*
2224import dotty .tools .dotc .core .Symbols .{Symbol , defn }
25+ import dotty .tools .dotc .core .SymbolLoaders
2326import dotty .tools .dotc .interfaces
2427import dotty .tools .dotc .interactive .Completion
2528import dotty .tools .dotc .printing .SyntaxHighlighting
@@ -70,6 +73,7 @@ case class State(objectIndex: Int,
7073 quiet : Boolean ,
7174 context : Context ):
7275 def validObjectIndexes = (1 to objectIndex).filterNot(invalidObjectIndexes.contains(_))
76+ // def copy() = this
7377
7478/** Main REPL instance, orchestrating input, compilation and presentation */
7579class ReplDriver (settings : Array [String ],
@@ -94,7 +98,7 @@ class ReplDriver(settings: Array[String],
9498 initCtx.settings.YwithBestEffortTasty .name
9599 )
96100
97- private def setupRootCtx (settings : Array [String ], rootCtx : Context , previousOutputDir : Option [ AbstractFile ] = None ) = {
101+ private def setupRootCtx (settings : Array [String ], rootCtx : Context ) = {
98102 val incompatible = settings.intersect(incompatibleOptions)
99103 val filteredSettings =
100104 if ! incompatible.isEmpty then
@@ -107,7 +111,7 @@ class ReplDriver(settings: Array[String],
107111 case Some ((files, ictx)) => inContext(ictx) {
108112 shouldStart = true
109113 if files.nonEmpty then out.println(i " Ignoring spurious arguments: $files%, % " )
110- ictx.base.initialize(previousOutputDir )
114+ ictx.base.initialize()
111115 ictx
112116 }
113117 case None =>
@@ -540,30 +544,23 @@ class ReplDriver(settings: Array[String],
540544 if (existingClass.nonEmpty)
541545 out.println(s " The path ' $path' cannot be loaded, it contains a classfile that already exists on the classpath: ${existingClass.get}" )
542546 state
543- else
544- val prevClassPath = state.context.platform.classPath( using state.context).asClassPathString
545- val newClassPath = s " $prevClassPath${ JFile .pathSeparator}$path "
547+ else inContext(state.context) :
548+ val jarClassPath = ClassPathFactory .newClassPath(jarFile)
549+ val prevOutputDir = ctx.settings.outputDir.value
546550
547551 // add to compiler class path
548- val prevOutputDir = rootCtx.settings.outputDir.valueIn(rootCtx.settingsState)
549- val ctxToUse = initCtx.fresh
550- .setSetting(rootCtx.settings.classpath, newClassPath)
551- .setSetting(rootCtx.settings.outputDir, prevOutputDir) // reuse virtual output directory
552- rootCtx = setupRootCtx(
553- Array (),
554- ctxToUse,
555- previousOutputDir = Some (prevOutputDir)
556- )
557- val s = state.copy(context = rootCtx)
552+ ctx.platform.addToClassPath(jarClassPath)
553+ SymbolLoaders .mergeNewEntries(defn.RootClass , ClassPath .RootPackage , jarClassPath, ctx.platform.classPath)
558554
559555 // new class loader with previous output dir and specified jar
560- val prevClassLoader = rendering.classLoader()( using state.context)
556+ val prevClassLoader = rendering.classLoader()
561557 val jarClassLoader = fromURLsParallelCapable(
562- ClassPathFactory .newClassPath(jarFile)( using rootCtx) .asURLs, prevClassLoader)
558+ jarClassPath .asURLs, prevClassLoader)
563559 rendering.myClassLoader = new AbstractFileClassLoader (
564- rootCtx.settings.outputDir.valueIn(rootCtx.settingsState), jarClassLoader)
560+ prevOutputDir, jarClassLoader)
561+
565562 out.println(s " Added ' $path' to classpath. " )
566- s
563+ state
567564
568565 case TypeOf (expr) =>
569566 expr match {
0 commit comments