aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-03-21 18:39:35 +0100
committerMartin Odersky <odersky@gmail.com>2014-03-21 18:39:35 +0100
commit9b17c6c86f3150afa7b5b395c23ec3fdf9c14200 (patch)
tree61651354673a1fbbe2800d047e3dfd8211567af9
parent5f318bc925c227d2bce5cff31610803185b57f54 (diff)
downloaddotty-9b17c6c86f3150afa7b5b395c23ec3fdf9c14200.tar.gz
dotty-9b17c6c86f3150afa7b5b395c23ec3fdf9c14200.tar.bz2
dotty-9b17c6c86f3150afa7b5b395c23ec3fdf9c14200.zip
Fix of Fix of t1236: higher-kinded
Fix of d6df293d2120f2247198cb6646a23c338f7dcbbf. It turned out the original commit was faulty in that iterator.flatten did not typecheck. The problem is fixed in this commit and flatten is added to the collections test.
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala6
-rw-r--r--src/dotty/tools/dotc/core/Types.scala5
-rw-r--r--tests/pos/collections.scala19
3 files changed, 18 insertions, 12 deletions
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index d66d4069c..ce1c1e869 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -649,13 +649,13 @@ class TypeComparer(initctx: Context) extends DotClass {
val base = tp1.narrow
tparams.map(base.memberInfo)
}
- val hkArgs = tp2.argInfos
- hk.println(s"isSubTypeHK: args1 = $args1, hkargs = $hkArgs")
- val boundsOK = (args1 corresponds hkArgs)(isSubType)
+ val hkBounds = tp2.argInfos.map(_.asInstanceOf[TypeBounds])
+ val boundsOK = (hkBounds corresponds args1)(_ contains _)
val variancesOK =
argInfos1.nonEmpty || (tparams corresponds tp2.typeSymbol.name.hkVariances) { (tparam, v) =>
v == 0 || tparam.variance == v
}
+ hk.println(s"isSubTypeHK: args1 = $args1, hk-bounds = $hkBounds $boundsOK $variancesOK")
boundsOK && variancesOK
}
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index e9c3c56b2..7cd66f5dd 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -1926,7 +1926,10 @@ object Types {
if (lo eq tp) this
else TypeAlias(tp, variance)
- def contains(tp: Type)(implicit ctx: Context) = lo <:< tp && tp <:< hi
+ def contains(tp: Type)(implicit ctx: Context) = tp match {
+ case tp: TypeBounds => lo <:< tp.lo && tp.hi <:< hi
+ case _ => lo <:< tp && tp <:< hi
+ }
def & (that: TypeBounds)(implicit ctx: Context): TypeBounds = {
val v = this commonVariance that
diff --git a/tests/pos/collections.scala b/tests/pos/collections.scala
index cd84f03d8..535e4b542 100644
--- a/tests/pos/collections.scala
+++ b/tests/pos/collections.scala
@@ -1,10 +1,10 @@
import scala.collection.generic.CanBuildFrom
object collections {
-
+
val arr = Array("a", "b")
val aa = arr ++ arr
-
+
List(1, 2, 3) map (x => 2)
val s = Set(1, 2, 3)
@@ -18,16 +18,19 @@ object collections {
val ints3: List[Int] = ints2
val f = (x: Int) => x + 1
val ints4: List[Int] = List(1, 2, 3, 5)
-
+
val ys = ints3 map (x => x + 1)
val zs = ys filter (y => y != 0)
-
+
val chrs = "abc"
-
+
def do2(x: Int, y: Char) = ()
-
+
chrs foreach println
-
+
(ints2, chrs).zipped foreach do2
-} \ No newline at end of file
+ val xs = List(List(1), List(2), List(3)).iterator
+ println(xs.flatten)
+
+}