Skip to content

Commit 58c1cf6

Browse files
committed
Improve comments around constrainPatternType
1 parent f9c8c14 commit 58c1cf6

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ trait PatternTypeConstrainer { self: TypeComparer =>
1414
/** Derive type and GADT constraints that necessarily follow from a pattern with the given type matching
1515
* a scrutinee of the given type.
1616
*
17-
* We have the following situation in case of a (dynamic) pattern match:
17+
* This function breaks down scrutinee and pattern types into subcomponents between which there must be
18+
* a subtyping relationship, and derives constraints from those relationships. We have the following situation
19+
* in case of a (dynamic) pattern match:
1820
*
1921
* StaticScrutineeType PatternType
2022
* \ /

compiler/src/dotty/tools/dotc/typer/Applications.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -1094,9 +1094,9 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
10941094
fullyDefinedType(unapplyArgType, "pattern selector", tree.span)
10951095
selType.dropAnnot(defn.UncheckedAnnot) // need to drop @unchecked. Just because the selector is @unchecked, the pattern isn't.
10961096
} else {
1097-
// note that we simply ignore whether constraining actually succeeded or not
1098-
// in theory, constraining should only fail if the pattern cannot possibly match
1099-
// however, during exhaustivity checks, we perform a strictly better check
1097+
// We ignore whether constraining the pattern succeeded.
1098+
// Constraining only fails if the pattern cannot possibly match,
1099+
// but useless pattern checks detect more such cases, so we simply rely on them instead.
11001100
ctx.addMode(Mode.GADTflexible).typeComparer.constrainPatternType(unapplyArgType, selType)
11011101
val patternBound = maximizeType(unapplyArgType, tree.span, fromScala2x)
11021102
if (patternBound.nonEmpty) unapplyFn = addBinders(unapplyFn, patternBound)

0 commit comments

Comments
 (0)