Skip to content

Commit 4bca332

Browse files
committed
Merge pull request #1005 from dotty-staging/ycheck-erasure-arrays
Ycheck that scala.Array is erazed to either Object or JavaArrayType.
2 parents 28c6b5a + 0290dbc commit 4bca332

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ object TypeErasure {
3939
case _: ErasedValueType =>
4040
true
4141
case tp: TypeRef =>
42-
tp.symbol.isClass && tp.symbol != defn.AnyClass
42+
tp.symbol.isClass && tp.symbol != defn.AnyClass && tp.symbol != defn.ArrayClass
4343
case _: TermRef =>
4444
true
4545
case JavaArrayType(elem) =>
@@ -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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ 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+
if (tp.typeSymbol == defn.ArrayClass &&
113+
ctx.compilationUnit.source.file.name == "Array.scala") {} // ok
114+
else
115+
assert(isErasedType(tp),
116+
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}")
113117
}
114118

115119
object Erasure extends TypeTestsCasts{

test/dotc/scala-collections.whitelist

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@
184184
./scala-scala/src/library/scala/collection/SeqViewLike.scala
185185
./scala-scala/src/library/scala/collection/mutable/IndexedSeqView.scala
186186
./scala-scala/src/library/scala/collection/immutable/StreamViewLike.scala
187-
188-
## This class causes a crash in backend -> @darkdimius
189-
#./scala-scala/src/library/scala/collection/immutable/TrieIterator.scala
187+
./scala-scala/src/library/scala/collection/immutable/TrieIterator.scala
190188

191189
./scala-scala/src/library/scala/collection/immutable/HashMap.scala
192190
./scala-scala/src/library/scala/collection/immutable/HashSet.scala

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+
}

tests/pos/i996.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)