From ae0cde4163ce7bcb0d4dffc98bdd45d241cec2e0 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 25 Jun 2015 22:03:01 +0200 Subject: [PATCH 1/2] Fix erasure of Thistypes. Thistypes erased to the underlying class. This is wrong. When seen as part of some other type, a ThisType has to erase to the erasure of the underlying type (i.e. the erasure if the selftype of the class). unittest-collections.scala failed with a MethodNotFound error because the erasure was computed incorrectly. On the other hand, a tree with a ThisType type, should keep the type, analogous to a tree with a TermRef type. --- src/dotty/tools/dotc/core/TypeErasure.scala | 6 +----- src/dotty/tools/dotc/transform/Erasure.scala | 1 + tests/{pending => }/run/unittest_collection.check | 0 tests/{pending => }/run/unittest_collection.scala | 10 +++++----- 4 files changed, 7 insertions(+), 10 deletions(-) rename tests/{pending => }/run/unittest_collection.check (100%) rename tests/{pending => }/run/unittest_collection.scala (86%) diff --git a/src/dotty/tools/dotc/core/TypeErasure.scala b/src/dotty/tools/dotc/core/TypeErasure.scala index 92e32d4b1c12..01c47d1357c2 100644 --- a/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/src/dotty/tools/dotc/core/TypeErasure.scala @@ -308,12 +308,8 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean val parent = tp.parent if (parent isRef defn.ArrayClass) eraseArray(tp) else this(parent) - case tp: TermRef => + case _: TermRef | _: ThisType => this(tp.widen) - case tp: ThisType => - def thisTypeErasure(tpToErase: Type) = - erasureFn(isJava, semiEraseVCs = false, isConstructor, wildcardOK)(tpToErase) - thisTypeErasure(tp.cls.typeRef) case SuperType(thistpe, supertpe) => SuperType(this(thistpe), this(supertpe)) case ExprType(rt) => diff --git a/src/dotty/tools/dotc/transform/Erasure.scala b/src/dotty/tools/dotc/transform/Erasure.scala index 962297517fad..5b6420aa224d 100644 --- a/src/dotty/tools/dotc/transform/Erasure.scala +++ b/src/dotty/tools/dotc/transform/Erasure.scala @@ -271,6 +271,7 @@ object Erasure extends TypeTestsCasts{ def erasedType(tree: untpd.Tree, semiEraseVCs: Boolean = true)(implicit ctx: Context): Type = tree.typeOpt match { case tp: TermRef if tree.isTerm => erasedRef(tp) + case tp: ThisType => tp case tp => erasure(tp, semiEraseVCs) } diff --git a/tests/pending/run/unittest_collection.check b/tests/run/unittest_collection.check similarity index 100% rename from tests/pending/run/unittest_collection.check rename to tests/run/unittest_collection.check diff --git a/tests/pending/run/unittest_collection.scala b/tests/run/unittest_collection.scala similarity index 86% rename from tests/pending/run/unittest_collection.scala rename to tests/run/unittest_collection.scala index d10845475b74..5db9b56d2bdc 100644 --- a/tests/pending/run/unittest_collection.scala +++ b/tests/run/unittest_collection.scala @@ -4,11 +4,11 @@ object Test { def main(args: Array[String]): Unit = { test(collection.mutable.ArrayBuffer[String]()) - test(collection.mutable.ListBuffer[String]()) - class BBuf(z:ListBuffer[String]) extends BufferProxy[String] { - def self = z - } - test(new BBuf(collection.mutable.ListBuffer[String]())) +// test(collection.mutable.ListBuffer[String]()) +// class BBuf(z:ListBuffer[String]) extends BufferProxy[String] { +// def self = z +// } +// test(new BBuf(collection.mutable.ListBuffer[String]())) } def test(x: Buffer[String]): Unit = { From 1de7de17d03c85276778917a2513764a659e8f5f Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 25 Jun 2015 22:50:07 +0200 Subject: [PATCH 2/2] Remove check file. The file consisted of just a deprecation warning. Not sure what was deprecated; neither dotty nor scalac find anything wrong with it. --- tests/run/unittest_collection.check | 1 - 1 file changed, 1 deletion(-) delete mode 100644 tests/run/unittest_collection.check diff --git a/tests/run/unittest_collection.check b/tests/run/unittest_collection.check deleted file mode 100644 index df1629dd7eb1..000000000000 --- a/tests/run/unittest_collection.check +++ /dev/null @@ -1 +0,0 @@ -warning: there was one deprecation warning; re-run with -deprecation for details