summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2012-05-10 13:48:32 +0200
committerLukas Rytz <lukas.rytz@epfl.ch>2012-05-10 13:53:41 +0200
commit23afe3c9b9ff6f1c9d31cea678909003ca8f943b (patch)
tree232440a6ded5f3ed38b20e455aee3c301db56f80
parentaa555debf77eeec3a72a1d700f06347d2e489299 (diff)
downloadscala-23afe3c9b9ff6f1c9d31cea678909003ca8f943b.tar.gz
scala-23afe3c9b9ff6f1c9d31cea678909003ca8f943b.tar.bz2
scala-23afe3c9b9ff6f1c9d31cea678909003ca8f943b.zip
Fix for SI-5654.
More details as code comment and in the bug database.
-rw-r--r--src/compiler/scala/reflect/internal/transform/Erasure.scala9
-rw-r--r--test/files/pos/t5654.scala13
2 files changed, 21 insertions, 1 deletions
diff --git a/src/compiler/scala/reflect/internal/transform/Erasure.scala b/src/compiler/scala/reflect/internal/transform/Erasure.scala
index 1b323f839b..5beec70d62 100644
--- a/src/compiler/scala/reflect/internal/transform/Erasure.scala
+++ b/src/compiler/scala/reflect/internal/transform/Erasure.scala
@@ -17,7 +17,14 @@ trait Erasure {
* with primitive as well as class types)?.
*/
private def genericCore(tp: Type): Type = tp.normalize match {
- case TypeRef(_, sym, _) if sym.isAbstractType && !sym.owner.isJavaDefined =>
+ /* A Java Array<T> is erased to Array[Object] (T can only be a reference type), where as a Scala Array[T] is
+ * erased to Object. However, there is only symbol for the Array class. So to make the distinction between
+ * a Java and a Scala array, we check if the owner of T comes from a Java class.
+ * This however caused issue SI-5654. The additional test for EXSITENTIAL fixes it, see the ticket comments.
+ * In short, members of an existential type (e.g. `T` in `forSome { type T }`) can have pretty arbitrary
+ * owners (e.g. when computing lubs, <root> is used). All packageClass symbols have `isJavaDefined == true`.
+ */
+ case TypeRef(_, sym, _) if sym.isAbstractType && (!sym.owner.isJavaDefined || sym.hasFlag(Flags.EXISTENTIAL)) =>
tp
case ExistentialType(tparams, restp) =>
genericCore(restp)
diff --git a/test/files/pos/t5654.scala b/test/files/pos/t5654.scala
new file mode 100644
index 0000000000..1f8d05bfed
--- /dev/null
+++ b/test/files/pos/t5654.scala
@@ -0,0 +1,13 @@
+class T(val a: Array[_])
+
+class U {
+ val a = Array(Array(1, 2), Array("a","b"))
+}
+
+class T1 { val a: Array[_] = Array(1) }
+
+case class Bomb(a: Array[_])
+case class Bomb2(a: Array[T] forSome { type T })
+class Okay1(a: Array[_])
+case class Okay2(s: Seq[_])
+