Equality Type in Scala 2.10 Reflection API

I ran into a strange reflection problem in Scala 2.10.0 Milestone 4 , in which I cannot wrap my head, First for material that works as I expected:

scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._

scala> trait A[X]; trait B[Y] extends A[Y]
defined trait A
defined trait B

scala> typeOf[B[String]].parents
res0: List[reflect.runtime.universe.Type] = List(java.lang.Object, A[String])

scala> typeOf[B[String]].parents contains typeOf[A[String]]
res1: Boolean = true

Similarly (in the same session):

scala> trait D; trait E extends A[D]
defined trait D
defined trait E

scala> typeOf[E].parents
res2: List[reflect.runtime.universe.Type] = List(java.lang.Object, A[D])

scala> typeOf[E].parents contains typeOf[A[D]]
res3: Boolean = true

No surprises here: I can ask the type parents and get exactly what I expect. Now I essentially combine the two examples above:

scala> trait F extends A[String]
defined trait F

scala> typeOf[F].parents
res4: List[reflect.runtime.universe.Type] = List(java.lang.Object, A[String])

scala> typeOf[F].parents contains typeOf[A[String]]
res5: Boolean = false

I do not understand how this can be false. The same thing happens if I have Fextend A[Seq[D]], A[Int]etc. What generalization am I missing for this behavior to make sense?

+5
source share
2 answers

This is mistake. This morning, I was about to investigate and fix it.

Edit. , -, Scala API , . , , .

=:= , ==.

+6

:

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

, , : https://issues.scala-lang.org/browse/SI-5959 ( , REPL ).

+3

All Articles