Skip to content

Commit 5a8675b

Browse files
DarkDimiusodersky
authored andcommitted
Fix erasure of raw arrays
1 parent 5133124 commit 5a8675b

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
321321
val sym = tp.symbol
322322
if (!sym.isClass) this(tp.info)
323323
else if (semiEraseVCs && isDerivedValueClass(sym)) eraseDerivedValueClassRef(tp)
324+
else if (sym == defn.ArrayClass) apply(tp.appliedTo(TypeBounds.empty)) // i966 shows that we can hit a raw Array type.
324325
else eraseNormalClassRef(tp)
325326
case tp: RefinedType =>
326327
val parent = tp.parent

src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class Erasure extends Phase with DenotTransformer { thisTransformer =>
109109
}
110110

111111
def assertErased(tp: Type, tree: tpd.Tree = tpd.EmptyTree)(implicit ctx: Context): Unit =
112-
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}")
112+
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}")
113113
}
114114

115115
object Erasure extends TypeTestsCasts{

tests/pos/i966.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package scala
2+
package collection
3+
package immutable
4+
5+
import HashMap.{ HashTrieMap, HashMapCollision1, HashMap1 }
6+
import HashSet.{ HashTrieSet, HashSetCollision1, HashSet1 }
7+
8+
object i996{
9+
10+
private[this] def collisionToArray[T](x: Iterable[T]): Array[Iterable[T]] = (x match {
11+
case x: HashMapCollision1[_, _] => x.kvs.map(x => HashMap(x)).toArray
12+
case x: HashSetCollision1[_] => x.ks.map(x => HashSet(x)).toArray
13+
}).asInstanceOf[Array[Iterable[T]]]
14+
15+
}

0 commit comments

Comments
 (0)