Skip to content

Commit 9b17c6c

Browse files
committed
Fix of Fix of t1236: higher-kinded
Fix of d6df293. 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.
1 parent 5f318bc commit 9b17c6c

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,13 +649,13 @@ class TypeComparer(initctx: Context) extends DotClass {
649649
val base = tp1.narrow
650650
tparams.map(base.memberInfo)
651651
}
652-
val hkArgs = tp2.argInfos
653-
hk.println(s"isSubTypeHK: args1 = $args1, hkargs = $hkArgs")
654-
val boundsOK = (args1 corresponds hkArgs)(isSubType)
652+
val hkBounds = tp2.argInfos.map(_.asInstanceOf[TypeBounds])
653+
val boundsOK = (hkBounds corresponds args1)(_ contains _)
655654
val variancesOK =
656655
argInfos1.nonEmpty || (tparams corresponds tp2.typeSymbol.name.hkVariances) { (tparam, v) =>
657656
v == 0 || tparam.variance == v
658657
}
658+
hk.println(s"isSubTypeHK: args1 = $args1, hk-bounds = $hkBounds $boundsOK $variancesOK")
659659
boundsOK && variancesOK
660660
}
661661

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,10 @@ object Types {
19261926
if (lo eq tp) this
19271927
else TypeAlias(tp, variance)
19281928

1929-
def contains(tp: Type)(implicit ctx: Context) = lo <:< tp && tp <:< hi
1929+
def contains(tp: Type)(implicit ctx: Context) = tp match {
1930+
case tp: TypeBounds => lo <:< tp.lo && tp.hi <:< hi
1931+
case _ => lo <:< tp && tp <:< hi
1932+
}
19301933

19311934
def & (that: TypeBounds)(implicit ctx: Context): TypeBounds = {
19321935
val v = this commonVariance that

tests/pos/collections.scala

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import scala.collection.generic.CanBuildFrom
22

33
object collections {
4-
4+
55
val arr = Array("a", "b")
66
val aa = arr ++ arr
7-
7+
88
List(1, 2, 3) map (x => 2)
99

1010
val s = Set(1, 2, 3)
@@ -18,16 +18,19 @@ object collections {
1818
val ints3: List[Int] = ints2
1919
val f = (x: Int) => x + 1
2020
val ints4: List[Int] = List(1, 2, 3, 5)
21-
21+
2222
val ys = ints3 map (x => x + 1)
2323
val zs = ys filter (y => y != 0)
24-
24+
2525
val chrs = "abc"
26-
26+
2727
def do2(x: Int, y: Char) = ()
28-
28+
2929
chrs foreach println
30-
30+
3131
(ints2, chrs).zipped foreach do2
3232

33-
}
33+
val xs = List(List(1), List(2), List(3)).iterator
34+
println(xs.flatten)
35+
36+
}

0 commit comments

Comments
 (0)