Skip to content

Commit 01096ff

Browse files
committed
Document ConstraintHandling#subsumes
1 parent 7830069 commit 01096ff

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,20 @@ trait ConstraintHandling[AbstractContext] {
336336
* L2 <: L1, and
337337
* U1 <: U2
338338
*
339-
* Both `c1` and `c2` are required to derive from constraint `pre`, possibly
340-
* narrowing it with further bounds.
339+
* Both `c1` and `c2` are required to derive from constraint `pre`, without adding
340+
* any new type variables but possibly narrowing already registered ones with further bounds.
341341
*/
342342
protected final def subsumes(c1: Constraint, c2: Constraint, pre: Constraint)(implicit actx: AbstractContext): Boolean =
343343
if (c2 eq pre) true
344344
else if (c1 eq pre) false
345345
else {
346346
val saved = constraint
347347
try
348+
// We iterate over params of `pre`, instead of `c2` as the documentation may suggest.
349+
// As neither `c1` nor `c2` can have more params than `pre`, this only matters in one edge case.
350+
// Constraint#forallParams only iterates over params that can be directly constrained.
351+
// If `c2` has, compared to `pre`, instantiated a param and we iterated over params of `c2`,
352+
// we could miss that param being instantiated to an incompatible type in `c1`.
348353
pre.forallParams(p =>
349354
c1.contains(p) &&
350355
c2.upper(p).forall(c1.isLess(p, _)) &&

0 commit comments

Comments
 (0)