I came across the puzzling behavior of Type.=:= When applied to typical refinances. Consider:
import reflect.runtime.universe._ type T1 = AnyRef { def apply( name: String ): Unit def foo: String } type Base = { def apply( name: String ): Unit } type T2 = Base { def foo: String }
Given that Base is an alias for type refining, I expected that refining it by adding the foo member would enter the same type as if I defined foo directly in Base .
Or, in other words, I would expect that T1 and T2 denote completely equivalent types.
For the most part, the skalak seems to agree. As an example, I can pass an instance of T2 where an instance of T1 is expected:
def f( x: T1 ){} f( null: T2 )
And vice versa:
def g( x: T2 ){} g( null: T1 )
I can also request proof of T1 =:= T2 , and it compiles fine too:
implicitly[T1 =:= T2]
However , using scala reflection, I get completely different results:
scala> typeOf[T1] =:= typeOf[T2] res2: Boolean = false
So, is this a scala reflection error (I would have guessed so), or is there a fundamental reason (technical otherwise) why typeOf[T1] =:= typeOf[T2] will return false?
source share