Skip to content

Commit f94606a

Browse files
committed
Fix inter-dependencies in HK GADTs
1 parent 23844d3 commit f94606a

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ final class ProperGadtConstraint private(
124124

125125
// The replaced symbols are picked up here.
126126
addToConstraint(poly1, tvars)
127-
.reporting(i"added to constraint: $params%, %\n$debugBoundsDescription", gadts)
127+
.reporting(i"added to constraint: [$poly1] $params%, %\n$debugBoundsDescription", gadts)
128128
}
129129

130130
override def addBound(sym: Symbol, bound: Type, isUpper: Boolean)(implicit ctx: Context): Boolean = {
@@ -237,8 +237,11 @@ final class ProperGadtConstraint private(
237237
}
238238

239239
override def fullUpperBound(param: TypeParamRef)(implicit ctx: Context): Type =
240-
constraint.minUpper(param).foldLeft(nonParamBounds(param).hi) {
241-
(t, u) => t & externalize(u)
240+
constraint.minUpper(param).foldLeft(nonParamBounds(param).hi) { (t, u) =>
241+
val eu = externalize(u)
242+
// Any as the upper bound means "no bound", but if F is higher-kinded,
243+
// Any & F = F[_]; this is wrong for us so we need to short-circuit
244+
if t.isAny then eu else t & eu
242245
}
243246

244247
// ---- Private ----------------------------------------------------------

tests/pos/gadt-hk-ordering.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
object test {
2+
3+
enum KSUB[-F[_], +G[_]] {
4+
case Refl[S[_]]() extends KSUB[S, S]
5+
}
6+
7+
enum Thing[+F[_]] {
8+
case LBOption() extends Thing[Option];
9+
case
10+
}
11+
12+
def foo[F[_]](ksub: Option KSUB F) =
13+
ksub match {
14+
case KSUB.Refl() =>
15+
// we have (s is type parameter of KSUB.Refl):
16+
// f >: Option
17+
// s <: f
18+
val fi: F[Int] = Option(0)
19+
()
20+
}
21+
}

0 commit comments

Comments
 (0)