Skip to content

Commit

Permalink
Merge pull request scala#1005 from dotty-staging/ycheck-erasure-arrays
Browse files Browse the repository at this point in the history
Ycheck that scala.Array is erazed to either Object or JavaArrayType.
  • Loading branch information
DarkDimius committed Jan 4, 2016
2 parents 28c6b5a + 0290dbc commit 4bca332
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 1 addition & 3 deletions test/dotc/scala-collections.whitelist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions tests/pos/i966.scala
Original file line number Diff line number Diff line change
@@ -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]]]

}
15 changes: 15 additions & 0 deletions tests/pos/i996.scala
Original file line number Diff line number Diff line change
@@ -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]]]

}

0 comments on commit 4bca332

Please sign in to comment.