Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pshirshov opened this issue Aug 9, 2019 · 2 comments

Comments

@pshirshov
Copy link

commented Aug 9, 2019

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.

@pshirshov pshirshov changed the title scala-reflect produces inconsistent results for type boundaries on scala 2.13.0 scala-reflect produces inconsistent results for type boundaries obtained through etaExpand on scala 2.13.0 Aug 9, 2019

pshirshov added a commit to 7mind/izumi that referenced this issue Aug 9, 2019

pshirshov added a commit to 7mind/izumi that referenced this issue Aug 9, 2019

@SethTisue

This comment has been minimized.

Copy link
Member

commented Aug 9, 2019

there is some discussion at https://gitter.im/scala/contributors?at=5d4dde99d03a7c63e6fc4071 on whether this qualifies as a regression, or whether it's simply the kind of compiler-internals thing that might be expected to change in a minor release, let alone a major release

@SethTisue

This comment has been minimized.

Copy link
Member

commented Aug 10, 2019

the bisect script from adriaanm/binfu#5 should be useful for identifying the scala/scala PR where this behavior changed, which I think would be the single most important piece of information to have in hand, in order to discuss whether this is a regression or simply a behavior change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.