Skip to content
Prev Previous commit
Next Next commit
Improve comments around constrainPatternType
  • Loading branch information
abgruszecki committed Jun 5, 2019
commit 3902ed26b53595f6eb03fb77ef9b3268a08089a3
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ trait PatternTypeConstrainer { self: TypeComparer =>
/** Derive type and GADT constraints that necessarily follow from a pattern with the given type matching
* a scrutinee of the given type.
*
* We have the following situation in case of a (dynamic) pattern match:
* This function breaks down scrutinee and pattern types into subcomponents between which there must be
* a subtyping relationship, and derives constraints from those relationships. We have the following situation
* in case of a (dynamic) pattern match:
*
* StaticScrutineeType PatternType
* \ /
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1095,9 +1095,9 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
fullyDefinedType(unapplyArgType, "pattern selector", tree.span)
selType.dropAnnot(defn.UncheckedAnnot) // need to drop @unchecked. Just because the selector is @unchecked, the pattern isn't.
} else {
// note that we simply ignore whether constraining actually succeeded or not
// in theory, constraining should only fail if the pattern cannot possibly match
// however, during exhaustivity checks, we perform a strictly better check
// We ignore whether constraining the pattern succeeded.
// Constraining only fails if the pattern cannot possibly match,
// but useless pattern checks detect more such cases, so we simply rely on them instead.
ctx.addMode(Mode.GADTflexible).typeComparer.constrainPatternType(unapplyArgType, selType)
val patternBound = maximizeType(unapplyArgType, tree.span, fromScala2x)
if (patternBound.nonEmpty) unapplyFn = addBinders(unapplyFn, patternBound)
Expand Down