@@ -8,6 +8,7 @@ import dotty.tools.dotc.Driver
88import dotty .tools .dotc .core .Contexts , Contexts .{ Context , ctx }
99import dotty .tools .io .{ PlainDirectory , Directory , ClassPath }
1010import Util .*
11+ import dotty .tools .dotc .util .SourceFile
1112
1213class StringDriver (compilerArgs : Array [String ], scalaSource : String ) extends Driver :
1314 override def sourcesRequired : Boolean = false
@@ -18,11 +19,12 @@ class StringDriver(compilerArgs: Array[String], scalaSource: String) extends Dri
1819
1920 setup(compilerArgs, initCtx.fresh) match
2021 case Some ((toCompile, rootCtx)) =>
21- given Context = rootCtx.fresh.setSetting(rootCtx.settings.outputDir,
22- new PlainDirectory (Directory (outDir)))
22+ given Context = rootCtx.fresh.setSetting(rootCtx.settings.outputDir, new PlainDirectory (Directory (outDir)))
2323
2424 val compiler = newCompiler
25- compiler.newRun.compileFromStrings(List (scalaSource))
25+
26+ val source = SourceFile .virtual(" expression" , scalaSource)
27+ compiler.newRun.compileSources(List (source))
2628
2729 val output = ctx.settings.outputDir.value
2830 if ctx.reporter.hasErrors then
@@ -39,7 +41,7 @@ class StringDriver(compilerArgs: Array[String], scalaSource: String) extends Dri
3941 case Left (ex) => Some (ex)
4042 catch
4143 case e : java.lang.reflect.InvocationTargetException =>
42- throw e.getCause
44+ Some ( e.getCause)
4345 finally
4446 deleteFile(outDir.toFile)
4547 case None => None
0 commit comments