Scala internal compilation. Work with interactive.Global

I am trying to extract an AST from a scala suce file. I simplified the code (only the corresponding code) to the following.

trait GetAST {
     val settings = new Settings
     val global = new Global(settings, new ConsoleReporter(settings))
     def getSt = "hello" //global.typedTree(src, true)
}
object Tre extends GetAST {
    def main(args:Array[String])
    {
        println(getSt.getClass)
        println("exiting program")
    }
}

The above code compiles and works fine. But the problem is that the program does not exit. After printing, “exit the program”, the invitation does not appear. I have to use ^ c to exit. Any idea what might be the problem

+3
source share
2 answers

I think Michael is right, the compiler uses Threads, and therefore the JVM does not just exit.

The good news is that it interactive.Globalmixes in the dash interactive.CompilerControl, a method askShutdownthat you can call at the end of your main one for the program to exit.

+3

, Settings, Global ConsoleReporter . , . JVM , ( ). . .

, Settings Global, , .

+2

Source: https://habr.com/ru/post/1744727/


All Articles