Skip to content

Commit ea1815d

Browse files
committed
Improve GadtConstraint comment
1 parent 824108c commit ea1815d

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,19 @@ final class ProperGadtConstraint private(
102102
else addLess(boundTvar.origin, symTvar.origin)
103103
case bound =>
104104
val oldUpperBound = bounds(symTvar.origin)
105-
// If we already have bounds `F >: [t] => List[t] <: [t] => Any`
106-
// and we want to record that `F <: [+A] => List[A]`, we need to adapt
107-
// type parameter variances of the bound. Consider that the following is valid:
105+
// If we have bounds:
106+
// F >: [t] => List[t] <: [t] => Any
107+
// and we want to record that:
108+
// F <: [+A] => List[A]
109+
// we need to adapt the variance and instead record that:
110+
// F <: [A] => List[A]
111+
// We cannot record the original bound, since it is false that:
112+
// [t] => List[t] <: [+A] => List[A]
108113
//
109-
// class Foo[F[t] >: List[t]]
110-
// type T = Foo[List]
111-
//
112-
// precisely because `Foo[List]` is desugared to `Foo[[A] => List[A]]`.
114+
// Note that the following code is accepted:
115+
// class Foo[F[t] >: List[t]]
116+
// type T = Foo[List]
117+
// precisely because Foo[List] is desugared to Foo[[A] => List[A]].
113118
val bound1 = bound.adaptHkVariances(oldUpperBound)
114119
if (isUpper) addUpperBound(symTvar.origin, bound1)
115120
else addLowerBound(symTvar.origin, bound1)

0 commit comments

Comments
 (0)