From 0ec9c927941ab3155d0c5edacfe3a21c8c4b74ca Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 19 Jun 2015 10:25:35 +0200 Subject: Fix checking whether types are instantiable. The logic for checking aginst the self type was wrong, as demonstrated by pos/checkInstantiable.scala. --- tests/pending/run/collections.check | 42 ------------- tests/pending/run/collections.scala | 119 ------------------------------------ tests/pos/checkInstantiable.scala | 5 ++ tests/run/collections.check | 42 +++++++++++++ tests/run/collections.scala | 119 ++++++++++++++++++++++++++++++++++++ 5 files changed, 166 insertions(+), 161 deletions(-) delete mode 100644 tests/pending/run/collections.check delete mode 100644 tests/pending/run/collections.scala create mode 100644 tests/pos/checkInstantiable.scala create mode 100644 tests/run/collections.check create mode 100644 tests/run/collections.scala (limited to 'tests') diff --git a/tests/pending/run/collections.check b/tests/pending/run/collections.check deleted file mode 100644 index c24150b24..000000000 --- a/tests/pending/run/collections.check +++ /dev/null @@ -1,42 +0,0 @@ -***** mutable.HashSet: -test1: 14005 -test2: 25005003, iters = 5000 -test3: 25005003 -***** mutable.LinkedHashSet: -test1: 14005 -test2: 25005003, iters = 5000 -test3: 25005003 -***** immutable.Set: -test1: 14005 -test2: 25005003, iters = 5000 -test3: 25005003 -***** immutable.ListSet: -test1: 14005 -test2: 25005003, iters = 5000 -test3: 25005003 -***** immutable.TreeSet: -test1: 14005 -test2: 25005003, iters = 5000 -test3: 25005003 -***** mutable.HashMap: -test1: 14005 -test2: 25005003, iters = 5000 -test3: 25005003 -***** mutable.LinkedHashMap: -test1: 14005 -test2: 25005003, iters = 5000 -test3: 25005003 -***** immutable.Map: -test1: 14005 -test2: 25005003, iters = 5000 -test3: 25005003 -test4: 25005003 -***** immutable.TreeMap: -test1: 14005 -test2: 25005003, iters = 5000 -test3: 25005003 -test4: 25005003 -***** immutable.ListMap: -test1: 14005 -test2: 9007003, iters = 3000 -test3: 9007003 diff --git a/tests/pending/run/collections.scala b/tests/pending/run/collections.scala deleted file mode 100644 index acc2d93ff..000000000 --- a/tests/pending/run/collections.scala +++ /dev/null @@ -1,119 +0,0 @@ -import scala.collection._ -import scala.compat.Platform.currentTime -import scala.language.postfixOps - -object Test extends dotty.runtime.LegacyApp { - - val printTime = false - - def sum[A](xs: Iterable[Int]) = (0 /: xs)((x, y) => x + y) - - def time(op: => Unit): Unit = { - val start = currentTime - op - if (printTime) println(" time = "+(currentTime - start)+"ms") - } - - def test(msg: String, s0: collection.immutable.Set[Int], iters: Int) = { - println("***** "+msg+":") - var s = s0 - s = s + 2 - s = s + (3, 4000, 10000) - println("test1: "+sum(s)) - time { - s = s ++ (List.range(0, iters) map (2*)) - println("test2: "+sum(s)+", iters = "+iters) - } - time { - var x = 0 - for (i <- 0 to 10000) - if (s contains i) x += i - println("test3: "+x) - } - } - - def test(msg: String, s0: collection.mutable.Set[Int], iters: Int) = { - println("***** "+msg+":") - var s = s0 - s = s + 2 - s = s + (3, 4000, 10000) - println("test1: "+sum(s)) - time { - s = s ++ (List.range(0, iters) map (2*)) - println("test2: "+sum(s)+", iters = "+iters) - } - time { - var x = 0 - for (i <- 0 to 10000) - if (s contains i) x += i - println("test3: "+x) - } - } - - def test(msg: String, s0: collection.immutable.Map[Int, Int], iters: Int) = { - println("***** "+msg+":") - var s = s0 - s = s + (2 -> 2) - s = s + (3 -> 3, 4000 -> 4000, 10000 -> 10000) - println("test1: "+sum(s map (_._2))) - time { - s = s ++ (List.range(0, iters) map (x => x * 2 -> x * 2)) - println("test2: "+sum(s map (_._2))+", iters = "+iters) - } - time { - var x = 0 - for (i <- 0 to 10000) - s get i match { - case Some(i) => x += i - case None => - } - println("test3: "+x) - } - if (iters == 5000) { - time { - var s1 = s - var x = 0 - for (i <- 0 to 10000) { - s get i match { - case Some(i) => x += i - case None => - } - s1 = s1 + ((i + 10000) -> i) - } - println("test4: "+x) - } - } - } - - def test(msg: String, s0: collection.mutable.Map[Int, Int], iters: Int) = { - println("***** "+msg+":") - var s = s0 - s = s + (2 -> 2) - s = s + (3 -> 3, 4000 -> 4000, 10000 -> 10000) - println("test1: "+sum(s map (_._2))) - time { - s = s ++ (List.range(0, iters) map (x => x * 2 -> x * 2)) - println("test2: "+sum(s map (_._2))+", iters = "+iters) - } - time { - var x = 0 - for (i <- 0 to 10000) - s get i match { - case Some(i) => x += i - case None => - } - println("test3: "+x) - } - } - - test("mutable.HashSet", new mutable.HashSet[Int], 5000) - test("mutable.LinkedHashSet", new mutable.LinkedHashSet[Int], 5000) - test("immutable.Set", immutable.Set[Int](), 5000) - test("immutable.ListSet", new immutable.ListSet[Int], 5000) - test("immutable.TreeSet", new immutable.TreeSet[Int], 5000) - test("mutable.HashMap", new mutable.HashMap[Int, Int], 5000) - test("mutable.LinkedHashMap", new mutable.LinkedHashMap[Int, Int], 5000) - test("immutable.Map", immutable.Map[Int, Int](), 5000) - test("immutable.TreeMap", new immutable.TreeMap[Int, Int], 5000) - test("immutable.ListMap", new immutable.ListMap[Int, Int], 3000) -} diff --git a/tests/pos/checkInstantiable.scala b/tests/pos/checkInstantiable.scala new file mode 100644 index 000000000..c8b166b1e --- /dev/null +++ b/tests/pos/checkInstantiable.scala @@ -0,0 +1,5 @@ +// check instantiable of parameterized self type +class LS[T] { self: LS[T] => } +object Test { + new LS[Int] +} diff --git a/tests/run/collections.check b/tests/run/collections.check new file mode 100644 index 000000000..c24150b24 --- /dev/null +++ b/tests/run/collections.check @@ -0,0 +1,42 @@ +***** mutable.HashSet: +test1: 14005 +test2: 25005003, iters = 5000 +test3: 25005003 +***** mutable.LinkedHashSet: +test1: 14005 +test2: 25005003, iters = 5000 +test3: 25005003 +***** immutable.Set: +test1: 14005 +test2: 25005003, iters = 5000 +test3: 25005003 +***** immutable.ListSet: +test1: 14005 +test2: 25005003, iters = 5000 +test3: 25005003 +***** immutable.TreeSet: +test1: 14005 +test2: 25005003, iters = 5000 +test3: 25005003 +***** mutable.HashMap: +test1: 14005 +test2: 25005003, iters = 5000 +test3: 25005003 +***** mutable.LinkedHashMap: +test1: 14005 +test2: 25005003, iters = 5000 +test3: 25005003 +***** immutable.Map: +test1: 14005 +test2: 25005003, iters = 5000 +test3: 25005003 +test4: 25005003 +***** immutable.TreeMap: +test1: 14005 +test2: 25005003, iters = 5000 +test3: 25005003 +test4: 25005003 +***** immutable.ListMap: +test1: 14005 +test2: 9007003, iters = 3000 +test3: 9007003 diff --git a/tests/run/collections.scala b/tests/run/collections.scala new file mode 100644 index 000000000..acc2d93ff --- /dev/null +++ b/tests/run/collections.scala @@ -0,0 +1,119 @@ +import scala.collection._ +import scala.compat.Platform.currentTime +import scala.language.postfixOps + +object Test extends dotty.runtime.LegacyApp { + + val printTime = false + + def sum[A](xs: Iterable[Int]) = (0 /: xs)((x, y) => x + y) + + def time(op: => Unit): Unit = { + val start = currentTime + op + if (printTime) println(" time = "+(currentTime - start)+"ms") + } + + def test(msg: String, s0: collection.immutable.Set[Int], iters: Int) = { + println("***** "+msg+":") + var s = s0 + s = s + 2 + s = s + (3, 4000, 10000) + println("test1: "+sum(s)) + time { + s = s ++ (List.range(0, iters) map (2*)) + println("test2: "+sum(s)+", iters = "+iters) + } + time { + var x = 0 + for (i <- 0 to 10000) + if (s contains i) x += i + println("test3: "+x) + } + } + + def test(msg: String, s0: collection.mutable.Set[Int], iters: Int) = { + println("***** "+msg+":") + var s = s0 + s = s + 2 + s = s + (3, 4000, 10000) + println("test1: "+sum(s)) + time { + s = s ++ (List.range(0, iters) map (2*)) + println("test2: "+sum(s)+", iters = "+iters) + } + time { + var x = 0 + for (i <- 0 to 10000) + if (s contains i) x += i + println("test3: "+x) + } + } + + def test(msg: String, s0: collection.immutable.Map[Int, Int], iters: Int) = { + println("***** "+msg+":") + var s = s0 + s = s + (2 -> 2) + s = s + (3 -> 3, 4000 -> 4000, 10000 -> 10000) + println("test1: "+sum(s map (_._2))) + time { + s = s ++ (List.range(0, iters) map (x => x * 2 -> x * 2)) + println("test2: "+sum(s map (_._2))+", iters = "+iters) + } + time { + var x = 0 + for (i <- 0 to 10000) + s get i match { + case Some(i) => x += i + case None => + } + println("test3: "+x) + } + if (iters == 5000) { + time { + var s1 = s + var x = 0 + for (i <- 0 to 10000) { + s get i match { + case Some(i) => x += i + case None => + } + s1 = s1 + ((i + 10000) -> i) + } + println("test4: "+x) + } + } + } + + def test(msg: String, s0: collection.mutable.Map[Int, Int], iters: Int) = { + println("***** "+msg+":") + var s = s0 + s = s + (2 -> 2) + s = s + (3 -> 3, 4000 -> 4000, 10000 -> 10000) + println("test1: "+sum(s map (_._2))) + time { + s = s ++ (List.range(0, iters) map (x => x * 2 -> x * 2)) + println("test2: "+sum(s map (_._2))+", iters = "+iters) + } + time { + var x = 0 + for (i <- 0 to 10000) + s get i match { + case Some(i) => x += i + case None => + } + println("test3: "+x) + } + } + + test("mutable.HashSet", new mutable.HashSet[Int], 5000) + test("mutable.LinkedHashSet", new mutable.LinkedHashSet[Int], 5000) + test("immutable.Set", immutable.Set[Int](), 5000) + test("immutable.ListSet", new immutable.ListSet[Int], 5000) + test("immutable.TreeSet", new immutable.TreeSet[Int], 5000) + test("mutable.HashMap", new mutable.HashMap[Int, Int], 5000) + test("mutable.LinkedHashMap", new mutable.LinkedHashMap[Int, Int], 5000) + test("immutable.Map", immutable.Map[Int, Int](), 5000) + test("immutable.TreeMap", new immutable.TreeMap[Int, Int], 5000) + test("immutable.ListMap", new immutable.ListMap[Int, Int], 3000) +} -- cgit v1.2.3