scala的诊断方法(4) -Ytyper-debug 编译项

在定位之前的那个问题时,发现了-Ytyper-debug选项,可以吧编译器在typer阶段的一些信息打印出来,比-Xprint:typer多出一些类型推导的信息:

$ cat A.scala
object A {
    println(1,2,3)
}

$ scalac -Ytyper-debug  A.scala
|-- <empty> EXPRmode-POLYmode-QUALmode (site: package <root>)
|    \-> <empty>.type
|-- object A BYVALmode-EXPRmode (site: package <empty>)
|    |-- super EXPRmode-POLYmode-QUALmode (silent: <init> in A)
|    |    |-- this EXPRmode (silent: <init> in A)
|    |    |    \-> A.type
|    |    \-> A.type
|    |-- println(1, 2, 3) BYVALmode-EXPRmode (site: value <local A> in A)
|    |    |-- println BYVALmode-EXPRmode-FUNmode-POLYmode (silent: value <local A> in A)
|    |    |    \-> (x: Any)Unit <and> ()Unit
|    |    |-- scala.Tuple3(1, 2, 3) : pt=Any BYVALmode-EXPRmode (silent: value <local A> in A)
|    |    |    |-- scala.Tuple3 BYVALmode-EXPRmode-FUNmode-POLYmode (silent: value <local A> in A)
|    |    |    |    |-- scala.Tuple3.apply BYVALmode-EXPRmode-FUNmode-POLYmode (silent: value <local A> in A)
|    |    |    |    |    [adapt] [T1, T2, T3](_1: T1, _2: T2, _3: T3)(T1, T2, T3) adapted to [T1, T2, T3](_1: T1, _2: T2, _3: T3)(T1, T2, T3)
|    |    |    |    |    \-> (_1: T1, _2: T2, _3: T3)(T1, T2, T3)
|    |    |    |    [adapt] Tuple3.type adapted to [T1, T2, T3](_1: T1, _2: T2, _3: T3)(T1, T2, T3)
|    |    |    |    \-> (_1: T1, _2: T2, _3: T3)(T1, T2, T3)
|    |    |    |-- 1 BYVALmode-EXPRmode-POLYmode (silent: value <local A> in A)
|    |    |    |    \-> Int(1)
|    |    |    |-- 2 BYVALmode-EXPRmode-POLYmode (silent: value <local A> in A)
|    |    |    |    \-> Int(2)
|    |    |    |-- 3 BYVALmode-EXPRmode-POLYmode (silent: value <local A> in A)
|    |    |    |    \-> Int(3)
|    |    |    solving for (T1: ?T1, T2: ?T2, T3: ?T3)
|    |    |    \-> (Int, Int, Int)
|    |    \-> Unit
|    \-> [object A] A.type
|-- (_1: <?>, _2: <?>, _3: <?>)(T1, T2, T3) EXPRmode-FUNmode-POLYmode-TAPPmode (site: object A) implicits disabled
|    |-- new (Int, Int, Int) EXPRmode-POLYmode-QUALmode (site: object A) implicits disabled
|    |    \-> (Int, Int, Int)
|    \-> (_1: Int, _2: Int, _3: Int)(Int, Int, Int)

在解析的时候,对println(1,2,3)里的参数执行了Tuple3(1,2,3)最终参数识别成了Tuple3[Int,Int,Int]类型。暂没发现更大的价值,先记下来以后再补充。

Leave a Reply

Your email address will not be published. Required fields are marked *