From 473c8318b8206a3415acef27a880c78614dbe064 Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Sun, 20 Dec 2015 17:04:11 +0100 Subject: [PATCH 1/6] Minimize #996 --- tests/pos/i996.scala | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/pos/i996.scala diff --git a/tests/pos/i996.scala b/tests/pos/i996.scala new file mode 100644 index 000000000000..1fedc00238ff --- /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]]] + +} From 513312450fddff94371f6ca0afd2524e2a17eed9 Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Sun, 20 Dec 2015 17:05:29 +0100 Subject: [PATCH 2/6] TypeErasure.isErasedType: scala.Array is invalid after Erasure. It should either be erased to j.l.Object or replaced by JavaArrayType. --- src/dotty/tools/dotc/core/TypeErasure.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dotty/tools/dotc/core/TypeErasure.scala b/src/dotty/tools/dotc/core/TypeErasure.scala index 108d862a9914..b6d7e491d4b5 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) => From 79db79a87e6141c7148f50622b4add60188ae7cf Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Sun, 20 Dec 2015 17:12:13 +0100 Subject: [PATCH 3/6] Fix assertion in erasure to correctly print name of the phase. --- src/dotty/tools/dotc/transform/Erasure.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dotty/tools/dotc/transform/Erasure.scala b/src/dotty/tools/dotc/transform/Erasure.scala index 1b9b898f2140..b3979c5248f4 100644 --- a/src/dotty/tools/dotc/transform/Erasure.scala +++ b/src/dotty/tools/dotc/transform/Erasure.scala @@ -109,7 +109,7 @@ 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}") + 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{ From 5a8675b76e1b7bed1b21cfdde211ffd89063eb9a Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Sun, 20 Dec 2015 17:12:13 +0100 Subject: [PATCH 4/6] Fix erasure of raw arrays --- src/dotty/tools/dotc/core/TypeErasure.scala | 1 + src/dotty/tools/dotc/transform/Erasure.scala | 2 +- tests/pos/i966.scala | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i966.scala diff --git a/src/dotty/tools/dotc/core/TypeErasure.scala b/src/dotty/tools/dotc/core/TypeErasure.scala index b6d7e491d4b5..e4f91914bbc2 100644 --- a/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/src/dotty/tools/dotc/core/TypeErasure.scala @@ -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 1b9b898f2140..b3979c5248f4 100644 --- a/src/dotty/tools/dotc/transform/Erasure.scala +++ b/src/dotty/tools/dotc/transform/Erasure.scala @@ -109,7 +109,7 @@ 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}") + 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/tests/pos/i966.scala b/tests/pos/i966.scala new file mode 100644 index 000000000000..1fedc00238ff --- /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]]] + +} From c3be5073490be226fe2010c2ab445998257cf422 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 21 Dec 2015 11:59:56 +0100 Subject: [PATCH 5/6] Refine interdiction of Array after erasure Array is still allowed after erasure when compiling Array.scala. --- src/dotty/tools/dotc/transform/Erasure.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dotty/tools/dotc/transform/Erasure.scala b/src/dotty/tools/dotc/transform/Erasure.scala index b3979c5248f4..3445b4c444ec 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.prev}") + 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{ From 0290dbcbffd3833e23ad6e206ca6fd1cc56f1415 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 21 Dec 2015 12:00:11 +0100 Subject: [PATCH 6/6] Enable previously failing whitelist test --- test/dotc/scala-collections.whitelist | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/dotc/scala-collections.whitelist b/test/dotc/scala-collections.whitelist index 328d040c15bf..2abb16c1ec20 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