Skip to content

scala-reflect produces inconsistent results for type boundaries obtained through etaExpand on scala 2.13.0 #11673

@pshirshov

Description

@pshirshov

Let's consider this example (you may just copypaste it into scala shell):

import scala.language.experimental.macros
import scala.reflect.macros.blackbox
import scala.reflect.runtime.universe._

trait LightTypeTag { /*TODO*/ }

def makeTag[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[LightTypeTag] = {
  import c.universe._
  val tpe = implicitly[WeakTypeTag[T]].tpe
  println((tpe, tpe.hashCode, System.identityHashCode(tpe)))

  def test() = {
  tpe.etaExpand.resultType.dealias.typeArgs.map(_.dealias.resultType.typeSymbol.typeSignature).map {
    case tpe: TypeBoundsApi =>
      tpe.hi
  }.foreach {
    tpe =>
    println((tpe, tpe.hashCode, System.identityHashCode(tpe)))
  }
  }
  test()
  test()
  test()
  c.Expr[LightTypeTag](q"null")
}

def materialize1[T[_]]: LightTypeTag = macro makeTag[T[Nothing]]

materialize1[Enum]

On scala < 2.13 it prints

(Enum,-2104744931,1129119773)
(Enum[E],2055684080,910505843)
(Enum[E],2055684080,910505843)
(Enum[E],2055684080,910505843)

Which is expected.

On scala 2.13 it prints

(Enum,847238925,1831829645)
(Enum[E],-1086966789,342809115)
(Enum[E],-37304610,678306695)
(Enum[E],-500995075,606816495)

So, each invocation returns it's own, unique type boundary. And =:= check fails.

It works without etaExpand though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions