tree1構文木で表される式とtree2が同じ型かどうかを判断したい。の型チェック方法を使ってやってみましたがscala.tools.reflect.ToolBox、実際の Scala の型と矛盾しているようです。
ここでツールボックスを作成します。
scala> val tb = runtimeMirror(getClass.getClassLoader).mkToolBox()
tb: scala.tools.reflect.ToolBox[reflect.runtime.universe.type]
= scala.tools.reflect.ToolBoxFactory$ToolBoxImpl@1ad29bfd
型の不等式を報告します。
scala> tb.typecheck(tree1).tpe =:= tb.typecheck(tree2).tpe
res81: Boolean = false
タイプの表現を求めます:
scala> tb.typecheck(tree1).tpe
res82: tb.u.Type = st1 with st2{val x: X; val y: Y}
scala> tb.typecheck(tree2).tpe
res83: tb.u.Type = scala.AnyRef{val x: X; val y: Y}
これらのタイプが正常に統合されました。
scala> implicitly[st1 with st2{val x: X; val y: Y} =:= scala.AnyRef{val x: X; val y: Y}]
res84: =:=[st1 with st2{val x: X; val y: Y},AnyRef{val x: X; val y: Y}] = <function1>
最後のスニペットで行われているのと同じようなタイプの式をチェックしてtree1表現tree2することはできますか?
編集:最小限の定義
trait X
trait Y
type st1 = { val x: X }
type st2 = { val y: Y }
val s1: st1 = new { val x: X = new X {} }
val s2: st2 = new { val y: Y = new Y {} }
def foo(s1: st1, s2: st2): st1 with st2 { val x: X; val y: Y } = ???
val pure = new { val x: X = new X {}; val y: Y = new Y {}}
val tree1 = reify { foo(s1, s2) }.tree
val tree2 = reify { pure }.tree