2

以下简单示例(在 Scala 2.11.8 中运行):

import scala.tools.reflect.ToolBox
import scala.reflect.runtime.currentMirror

object Main extends App {

  val toolbox = currentMirror.mkToolBox()

  val tree = toolbox.parse {
    """
    package foo.bar {
       trait Baz
    }
    """
  }
  println(tree)

  val checkedTree = toolbox.typecheck(tree)
  println(tree)
}

导致以下异常toolbox.typecheck(tree)

Exception in thread "main" java.lang.AssertionError: assertion failed: value <local <expression-owner>>
    at scala.reflect.internal.Symbols$Symbol.newPackage(Symbols.scala:310)
    at scala.tools.nsc.typechecker.Namers$Namer.createPackageSymbol(Namers.scala:381)
    at scala.tools.nsc.typechecker.Namers$Namer.createPackageSymbol(Namers.scala:374)
    ...

如何获得经过类型检查的 AST 树?

4

0 回答 0