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

Uncurry is picky about its erasure decision (when it shouldn't) #9443

Open
scabug opened this issue Aug 22, 2015 · 1 comment
Open

Uncurry is picky about its erasure decision (when it shouldn't) #9443

scabug opened this issue Aug 22, 2015 · 1 comment

Comments

@scabug
Copy link

scabug commented Aug 22, 2015

Following up on #6443 and #9442, is seems the uncurry erasure is quite picky:

$ cat test2.scala 
trait Ctx {
  trait Tree
}
trait Lst[+A] {
  def zip[A1 >: A, B](that: Lst[B]): Nothing
}
object Test {
  def foo1(c: Ctx)(l: Lst[c.Tree]) = l zip l
  def foo2[T](c: Ctx)(l: Lst[c.Tree])(t: T) = l zip l
}

$ scalac test2.scala -Xprint:uncurry
[[syntax trees at end of                   uncurry]] // test2.scala
package <empty> {
  abstract trait Ctx extends Object {
    def /*Ctx*/$init$(): Unit = {
      ()
    };
    abstract trait Tree extends Object
  };
  abstract trait Lst[+A] extends Object {
    def zip[A1 >: A, B](that: Lst[B]): Nothing
  };
  object Test extends Object {
    def <init>(): Test.type = {
      Test.super.<init>();
      ()
    };
    def foo1(c: Ctx, l: Lst[Ctx#Tree]): Nothing = {
      <synthetic> val l$1: Lst[c.Tree] = l.asInstanceOf[Lst[c.Tree]]();
      l$1.zip[c.Tree, c.Tree](l$1)
    };
    def foo2[T](c: Ctx, l: Lst[c.Tree], t: T): Nothing = l.zip[c.Tree, c.Tree](l)
  }
}

So, depending on whether you have a type parameter, it decides to erase or not:

    def foo1(c: Ctx, l: Lst[Ctx#Tree]): Nothing = {
      <synthetic> val l$1: Lst[c.Tree] = l.asInstanceOf[Lst[c.Tree]]();
      l$1.zip[c.Tree, c.Tree](l$1)
    };
    def foo2[T](c: Ctx, l: Lst[c.Tree], t: T): Nothing = l.zip[c.Tree, c.Tree](l)

I think the problem lies in the isDependentMethodType method in class Type, but I may be wrong:

$ scala
Welcome to Scala 2.11.8-20150821-135328-f8a6d21a49 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_80).
Type in expressions for evaluation. Or try :help.

scala> trait Ctx {
     |   trait Tree
     | }
defined trait Ctx

scala> trait Lst[+A] {
     |   def zip[A1 >: A, B](that: Lst[B]): Nothing
     | }
defined trait Lst

scala> object Test {
     |   def foo1(c: Ctx)(l: Lst[c.Tree]) = l zip l
     |   def foo2[T](c: Ctx)(l: Lst[c.Tree])(t: T) = l zip l
     | }
defined object Test

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

scala> typeTag[Test.type].tpe.member(TermName("foo1")).info.asInstanceOf[scala.reflect.internal.Types#Type].isDependentMethodType
res0: Boolean = true

scala> typeTag[Test.type].tpe.member(TermName("foo2")).info.asInstanceOf[scala.reflect.internal.Types#Type].isDependentMethodType
res1: Boolean = false
@scabug
Copy link
Author

scabug commented Aug 22, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9443?orig=1
Reporter: @VladUreche
Affected Versions: 2.10.5, 2.11.7, 2.12.0-M2
See #6443, #9442

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant