Skip to content

Commit 2d9d0c9

Browse files
committed
Fix regression in instantiating type vars
1 parent ba481c6 commit 2d9d0c9

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4810,7 +4810,7 @@ object Types {
48104810
def hasLowerBound(using Context): Boolean = !currentEntry.loBound.isExactlyNothing
48114811

48124812
/** For uninstantiated type variables: Is the upper bound different from Any? */
4813-
def hasUpperBound(using Context): Boolean = !currentEntry.hiBound.finalResultType.isExactlyAny
4813+
def hasUpperBound(using Context): Boolean = !currentEntry.hiBound.finalResultType.isRef(defn.AnyClass) // so also `Any[..]`
48144814

48154815
/** Unwrap to instance (if instantiated) or origin (if not), until result
48164816
* is no longer a TypeVar

compiler/test/dotc/pos-test-pickling.blacklist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ i13871.scala
2020
i15181.scala
2121
i15922.scala
2222
t5031_2.scala
23+
i16997.scala
2324

2425
# Tree is huge and blows stack for printing Text
2526
i7034.scala

tests/pos/i16997.min.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Fn:
2+
class R[Y]
3+
4+
case class Foo[F[_]](nest: Foo[F]):
5+
case class Bar[G[_], R[_]](value: Foo[G])
6+
7+
def bar[G[_]](using fn: Fn): Bar[G, fn.R] = ???
8+
9+
def part[G[_]](using fn: Fn): Bar[G, fn.R] =
10+
(bar[G], ()) match
11+
case (Bar(value), ()) =>
12+
Bar(Foo(value))

tests/pos/i16997.scala

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
class Funs {
2+
sealed trait ->[A, B]
3+
}
4+
5+
/**
6+
* Binary tree with leafs holding values of types `F[X]`, `F[Y]`, ...
7+
* The complete structure of the tree is expressed by the type `A`, using the tags for branches and leafs.
8+
*
9+
* @tparam <*> tag for branches
10+
* @tparam T tag for leafs.
11+
* @tparam F value type of leafs. Each leaf holds a value of type `F[T]`, for some type `T`.
12+
* @tparam A captures the complete structure of the tree
13+
*/
14+
enum Tree[<*>[_, _], T[_], F[_], A] {
15+
case Branch[<*>[_, _], T[_], F[_], A, B](
16+
l: Tree[<*>, T, F, A],
17+
r: Tree[<*>, T, F, B],
18+
) extends Tree[<*>, T, F, A <*> B]
19+
20+
case Leaf[<*>[_, _], T[_], F[_], A](
21+
value: F[A],
22+
) extends Tree[<*>, T, F, T[A]]
23+
24+
def <*>[B](that: Tree[<*>, T, F, B]): Tree[<*>, T, F, A <*> B] =
25+
Branch(this, that)
26+
27+
def partition[G[_], H[_]](
28+
f: [x] => F[x] => Either[G[x], H[x]],
29+
)(using
30+
funs: Funs,
31+
): Partitioned[G, H, funs.->] =
32+
this match {
33+
case Leaf(a) =>
34+
f(a) match
35+
case Left(a) => Partitioned.Left(Leaf(a))
36+
case Right(a) => Partitioned.Right(Leaf(a))
37+
case Branch(l, r) =>
38+
import Partitioned.{Both, Left, Right}
39+
import l.Partitioned.{Both => LBoth, Left => LLeft, Right => LRight}
40+
import r.Partitioned.{Both => RBoth, Left => RLeft, Right => RRight}
41+
42+
(l.partition(f), r.partition(f)) match
43+
case (LLeft(lg), RLeft(rg)) => Left(lg <*> rg)
44+
case (LLeft(lg), RRight(rh)) => Both(lg, rh)
45+
case (LLeft(lg), RBoth(rg, rh)) => Both(lg <*> rg, rh)
46+
case (LRight(lh), RLeft(rg)) => Both(rg, lh)
47+
case (LRight(lh), RRight(rh)) => Right(lh <*> rh)
48+
case (LRight(lh), RBoth(rg, rh)) => Both(rg, lh <*> rh)
49+
case (LBoth(lg, lh), RLeft(rg)) => Both(lg <*> rg, lh)
50+
case (LBoth(lg, lh), RRight(rh)) => Both(lg, lh <*> rh)
51+
case (LBoth(lg, lh), RBoth(rg, rh)) => Both(lg <*> rg, lh <*> rh)
52+
}
53+
54+
// note that `->` is never even used, to keep this reproduction case small
55+
enum Partitioned[G[_], H[_], ->[_, _]] {
56+
case Left(value: Tree[<*>, T, G, A])
57+
case Right(value: Tree[<*>, T, H, A])
58+
case Both[G[_], H[_], X, Y, ->[_, _]](
59+
l: Tree[<*>, T, G, X],
60+
r: Tree[<*>, T, H, Y],
61+
) extends Partitioned[G, H, ->]
62+
}
63+
}

0 commit comments

Comments
 (0)