summaryrefslogtreecommitdiff
path: root/src/compiler/scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-07-01 16:24:36 +0000
committerPaul Phillips <paulp@improving.org>2011-07-01 16:24:36 +0000
commitdcc07bd9f0ce8c2f3ba1757047caa5919f4bc7c5 (patch)
tree8cb01983b75f31969ae40242349155d1606c2a42 /src/compiler/scala
parent60d0585371bb1c575f1c8e14893cea811029055f (diff)
downloadscala-dcc07bd9f0ce8c2f3ba1757047caa5919f4bc7c5.tar.gz
scala-dcc07bd9f0ce8c2f3ba1757047caa5919f4bc7c5.tar.bz2
scala-dcc07bd9f0ce8c2f3ba1757047caa5919f4bc7c5.zip
Fixed a bug involving classOf[Foo] having the w...
Fixed a bug involving classOf[Foo] having the wrong erasure. Luckily I had only days ago deciphered the unique handling of classOf, so I knew what was up. Closes #4753, review by odersky.
Diffstat (limited to 'src/compiler/scala')
-rw-r--r--src/compiler/scala/reflect/internal/TreeGen.scala3
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala11
2 files changed, 11 insertions, 3 deletions
diff --git a/src/compiler/scala/reflect/internal/TreeGen.scala b/src/compiler/scala/reflect/internal/TreeGen.scala
index 9d48d9d299..c17ab8be63 100644
--- a/src/compiler/scala/reflect/internal/TreeGen.scala
+++ b/src/compiler/scala/reflect/internal/TreeGen.scala
@@ -226,6 +226,9 @@ abstract class TreeGen {
* that the type given by classOf[T] is too strong and should be
* weakened so as not to suggest that classOf[List[String]] is any
* different from classOf[List[Int]].
+ *
+ * !!! See deconstMap in Erasure for one bug this encoding has induced:
+ * I would be very surprised if there aren't more.
*/
def mkClassOf(tp: Type): Tree =
Literal(Constant(tp)) setType ConstantType(Constant(tp))
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index 21bf696077..1c6e2e9f90 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -527,10 +527,15 @@ abstract class Erasure extends AddInterfaces
}
val deconstMap = new TypeMap {
+ // For some reason classOf[Foo] creates ConstantType(Constant(tpe)) with an actual Type for tpe,
+ // which is later translated to a Class. Unfortunately that means we have bugs like the erasure
+ // of Class[Foo] and classOf[Bar] not being seen as equivalent, leading to duplicate method
+ // generation and failing bytecode. See ticket #4753.
def apply(tp: Type): Type = tp match {
- case PolyType(_, _) => mapOver(tp)
- case MethodType(_, _) => mapOver(tp) // nullarymethod was eliminated during uncurry
- case _ => tp.deconst
+ case PolyType(_, _) => mapOver(tp)
+ case MethodType(_, _) => mapOver(tp) // nullarymethod was eliminated during uncurry
+ case ConstantType(Constant(_: Type)) => ClassClass.tpe // all classOfs erase to Class
+ case _ => tp.deconst
}
}
// Methods on Any/Object which we rewrite here while we still know what