Type equality in the Scala 2.10 Reflection API

浪子不回头ぞ 提交于 2019-12-05 09:17:33

That's a bug. Right this morning I was going to investigate and fix it.

Edit. this appears to be an implementation detail of Scala reflection API leaking to the userland. It's not easy to fix, so for now we leave it as it is, but will look into the possibilities to improve.

In the meanwhile, to get correct results, one should always use =:= to compare types, not ==.

Another illustration of the strangeness:

scala> val atype = typeOf[A[String]]
atype: reflect.runtime.universe.Type = A[String]

scala> val atype2 = typeOf[F].parents(1)
atype2: reflect.runtime.universe.Type = A[String]

scala> typeOf[F].parents contains atype
res39: Boolean = false

scala> typeOf[F].parents contains atype2
res40: Boolean = true

I think you're seeing a bug similar to this one: https://issues.scala-lang.org/browse/SI-5959 (although I've confirmed that this oddness occurs outside of the REPL too).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!