Skip to content
This repository
Browse code

SI-7120 Erasure must honor typeref prefixes

Erasure was discarding these, which led to unnecessarily
wide types in quite particular circumstances. This showed
up as a double definition error in the reported bug when the
bridge method clashed with the erased signature.
  • Loading branch information...
commit c11cf0b6c55cc2ec15820dceb6ba825726deed88 1 parent bafebe1
Jason Zaugg authored February 13, 2013
2  src/reflect/scala/reflect/internal/transform/Erasure.scala
@@ -130,7 +130,7 @@ trait Erasure {
130 130
         else if (sym.isRefinementClass) apply(mergeParents(tp.parents))
131 131
         else if (sym.isDerivedValueClass) eraseDerivedValueClassRef(tref)
132 132
         else if (sym.isClass) eraseNormalClassRef(pre, sym)
133  
-        else apply(sym.info) // alias type or abstract type
  133
+        else apply(sym.info asSeenFrom (pre, sym.owner)) // alias type or abstract type
134 134
       case PolyType(tparams, restpe) =>
135 135
         apply(restpe)
136 136
       case ExistentialType(tparams, restpe) =>
1  test/files/run/t7120.check
... ...
@@ -0,0 +1 @@
  1
+8
10  test/files/run/t7120/Base_1.scala
... ...
@@ -0,0 +1,10 @@
  1
+// This bug doesn't depend on separate compilation,
  2
+// in the interests of minimizing the log output during
  3
+// debugging this problem, I've split the compilation.
  4
+
  5
+case class Container( v: String )
  6
+
  7
+trait Base[ T <: AnyRef ] {
  8
+  type UserType = T
  9
+  protected def defect: PartialFunction[ UserType, String ]
  10
+}
9  test/files/run/t7120/Derived_2.scala
... ...
@@ -0,0 +1,9 @@
  1
+trait Derived extends Base[ Container ] {
  2
+  protected def defect = { case c: Container => c.v.toString }
  3
+}
  4
+
  5
+// Erasure was ignoring the prefix `Derived#7001.this` when erasing
  6
+// A1, and consequently used `Object` rather than `Container`, which
  7
+// was only seen because that signature clashed with the bridge method.
  8
+//
  9
+// applyOrElse[A1 <: Derived#7001.this.UserType#7318, B1 >: String](x1: A1)
3  test/files/run/t7120/Run_3.scala
... ...
@@ -0,0 +1,3 @@
  1
+object Test extends Derived with App {
  2
+  println( defect( Container( "8" ) ) )
  3
+}
2  test/files/run/t7120b.check
... ...
@@ -0,0 +1,2 @@
  1
+public int C$D.foo(java.lang.String)
  2
+public int C$D.foo(java.lang.String)
27  test/files/run/t7120b.scala
... ...
@@ -0,0 +1,27 @@
  1
+trait Base[A] { type B = A; }
  2
+class C extends Base[String] {
  3
+  class D {
  4
+    def foo[B1 <: B](b: B1) = 0
  5
+  }
  6
+}
  7
+
  8
+trait BaseHK[M[_], A] { type B = M[A]; }
  9
+object BaseHK { type Id[X] = X }
  10
+class CHK extends BaseHK[BaseHK.Id, String] {
  11
+  class D {
  12
+    def foo[B1 <: B](b: B1) = 0
  13
+  }
  14
+}
  15
+
  16
+
  17
+object Test extends App {
  18
+  val c = new C
  19
+  val d = new c.D()
  20
+  val meth = d.getClass.getMethods.find(_.getName == "foo").get
  21
+  println(meth)
  22
+
  23
+  val chk = new CHK
  24
+  val dhk = new chk.D()
  25
+  val methhk = d.getClass.getMethods.find(_.getName == "foo").get
  26
+  println(methhk)
  27
+}

0 notes on commit c11cf0b

Please sign in to comment.
Something went wrong with that request. Please try again.