aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Petrashko <dark@d-d.me>2016-01-04 10:46:01 +0100
committerDmitry Petrashko <dark@d-d.me>2016-01-04 10:46:01 +0100
commit4bca33233bb11e9a8ef8461b66707c37e8a09184 (patch)
treeb6877e3fc6f9b8cce3eb3cd62a593d15812a0c65
parent28c6b5a48122c26aff1a810c8f33c50a3643fd79 (diff)
parent0290dbcbffd3833e23ad6e206ca6fd1cc56f1415 (diff)
downloaddotty-4bca33233bb11e9a8ef8461b66707c37e8a09184.tar.gz
dotty-4bca33233bb11e9a8ef8461b66707c37e8a09184.tar.bz2
dotty-4bca33233bb11e9a8ef8461b66707c37e8a09184.zip
Merge pull request #1005 from dotty-staging/ycheck-erasure-arrays
Ycheck that scala.Array is erazed to either Object or JavaArrayType.
-rw-r--r--src/dotty/tools/dotc/core/TypeErasure.scala3
-rw-r--r--src/dotty/tools/dotc/transform/Erasure.scala6
-rw-r--r--test/dotc/scala-collections.whitelist4
-rw-r--r--tests/pos/i966.scala15
-rw-r--r--tests/pos/i996.scala15
5 files changed, 38 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/core/TypeErasure.scala b/src/dotty/tools/dotc/core/TypeErasure.scala
index 108d862a9..e4f91914b 100644
--- a/src/dotty/tools/dotc/core/TypeErasure.scala
+++ b/src/dotty/tools/dotc/core/TypeErasure.scala
@@ -39,7 +39,7 @@ object TypeErasure {
case _: ErasedValueType =>
true
case tp: TypeRef =>
- tp.symbol.isClass && tp.symbol != defn.AnyClass
+ tp.symbol.isClass && tp.symbol != defn.AnyClass && tp.symbol != defn.ArrayClass
case _: TermRef =>
true
case JavaArrayType(elem) =>
@@ -321,6 +321,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
val sym = tp.symbol
if (!sym.isClass) this(tp.info)
else if (semiEraseVCs && isDerivedValueClass(sym)) eraseDerivedValueClassRef(tp)
+ else if (sym == defn.ArrayClass) apply(tp.appliedTo(TypeBounds.empty)) // i966 shows that we can hit a raw Array type.
else eraseNormalClassRef(tp)
case tp: RefinedType =>
val parent = tp.parent
diff --git a/src/dotty/tools/dotc/transform/Erasure.scala b/src/dotty/tools/dotc/transform/Erasure.scala
index 1b9b898f2..3445b4c44 100644
--- a/src/dotty/tools/dotc/transform/Erasure.scala
+++ b/src/dotty/tools/dotc/transform/Erasure.scala
@@ -109,7 +109,11 @@ class Erasure extends Phase with DenotTransformer { thisTransformer =>
}
def assertErased(tp: Type, tree: tpd.Tree = tpd.EmptyTree)(implicit ctx: Context): Unit =
- assert(isErasedType(tp), i"The type $tp - ${tp.toString} of class ${tp.getClass} of tree $tree : ${tree.tpe} / ${tree.getClass} is illegal after erasure, phase = ${ctx.phase}")
+ if (tp.typeSymbol == defn.ArrayClass &&
+ ctx.compilationUnit.source.file.name == "Array.scala") {} // ok
+ else
+ assert(isErasedType(tp),
+ i"The type $tp - ${tp.toString} of class ${tp.getClass} of tree $tree : ${tree.tpe} / ${tree.getClass} is illegal after erasure, phase = ${ctx.phase.prev}")
}
object Erasure extends TypeTestsCasts{
diff --git a/test/dotc/scala-collections.whitelist b/test/dotc/scala-collections.whitelist
index 328d040c1..2abb16c1e 100644
--- a/test/dotc/scala-collections.whitelist
+++ b/test/dotc/scala-collections.whitelist
@@ -184,9 +184,7 @@
./scala-scala/src/library/scala/collection/SeqViewLike.scala
./scala-scala/src/library/scala/collection/mutable/IndexedSeqView.scala
./scala-scala/src/library/scala/collection/immutable/StreamViewLike.scala
-
-## This class causes a crash in backend -> @darkdimius
-#./scala-scala/src/library/scala/collection/immutable/TrieIterator.scala
+./scala-scala/src/library/scala/collection/immutable/TrieIterator.scala
./scala-scala/src/library/scala/collection/immutable/HashMap.scala
./scala-scala/src/library/scala/collection/immutable/HashSet.scala
diff --git a/tests/pos/i966.scala b/tests/pos/i966.scala
new file mode 100644
index 000000000..1fedc0023
--- /dev/null
+++ b/tests/pos/i966.scala
@@ -0,0 +1,15 @@
+package scala
+package collection
+package immutable
+
+import HashMap.{ HashTrieMap, HashMapCollision1, HashMap1 }
+import HashSet.{ HashTrieSet, HashSetCollision1, HashSet1 }
+
+object i996{
+
+ private[this] def collisionToArray[T](x: Iterable[T]): Array[Iterable[T]] = (x match {
+ case x: HashMapCollision1[_, _] => x.kvs.map(x => HashMap(x)).toArray
+ case x: HashSetCollision1[_] => x.ks.map(x => HashSet(x)).toArray
+ }).asInstanceOf[Array[Iterable[T]]]
+
+}
diff --git a/tests/pos/i996.scala b/tests/pos/i996.scala
new file mode 100644
index 000000000..1fedc0023
--- /dev/null
+++ b/tests/pos/i996.scala
@@ -0,0 +1,15 @@
+package scala
+package collection
+package immutable
+
+import HashMap.{ HashTrieMap, HashMapCollision1, HashMap1 }
+import HashSet.{ HashTrieSet, HashSetCollision1, HashSet1 }
+
+object i996{
+
+ private[this] def collisionToArray[T](x: Iterable[T]): Array[Iterable[T]] = (x match {
+ case x: HashMapCollision1[_, _] => x.kvs.map(x => HashMap(x)).toArray
+ case x: HashSetCollision1[_] => x.ks.map(x => HashSet(x)).toArray
+ }).asInstanceOf[Array[Iterable[T]]]
+
+}