Skip to content

Commit 0b2fa94

Browse files
committed
Remove unnecessary calls to constrainPatternType
constrainPatternType is specific to term patterns, whereas in match types there is a simple subtyping relationship between the pattern and the scrutinee. In the future, simply calling isSubType in GADTFlexible context would likely be sufficient.
1 parent a5cf2e8 commit 0b2fa94

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
10901090
* - If a type proxy P is not a reference to a class, P's supertype is in G
10911091
*/
10921092
def isSubTypeOfParent(subtp: Type, tp: Type)(implicit ctx: Context): Boolean =
1093-
if (constrainPatternType(subtp, tp, termPattern = true)) true
1093+
if (constrainPatternType(subtp, tp)) true
10941094
else tp match {
10951095
case tp: TypeRef if tp.symbol.isClass => isSubTypeOfParent(subtp, tp.firstParent)
10961096
case tp: TypeProxy => isSubTypeOfParent(subtp, tp.superType)

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,8 @@ object Inferencing {
184184
*
185185
* Invariant refinement can be assumed if `PatternType`'s class(es) are final or
186186
* case classes (because of `RefChecks#checkCaseClassInheritanceInvariant`).
187-
*
188-
* @param termPattern are we dealing with a term-level or a type-level pattern?
189187
*/
190-
def constrainPatternType(tp: Type, pt: Type, termPattern: Boolean)(implicit ctx: Context): Boolean = {
188+
def constrainPatternType(tp: Type, pt: Type)(implicit ctx: Context): Boolean = {
191189
def refinementIsInvariant(tp: Type): Boolean = tp match {
192190
case tp: ClassInfo => tp.cls.is(Final) || tp.cls.is(Case)
193191
case tp: TypeProxy => refinementIsInvariant(tp.underlying)
@@ -209,7 +207,7 @@ object Inferencing {
209207
}
210208

211209
val widePt = if (ctx.scala2Mode || refinementIsInvariant(tp)) pt else widenVariantParams(pt)
212-
val narrowTp = if (termPattern) SkolemType(tp) else tp
210+
val narrowTp = SkolemType(tp)
213211
trace(i"constraining pattern type $narrowTp <:< $widePt", gadts, res => s"$res\n${ctx.gadt.debugBoundsDescription}") {
214212
narrowTp <:< widePt
215213
}

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ class Typer extends Namer
604604
def handlePattern: Tree = {
605605
val tpt1 = typedTpt
606606
if (!ctx.isAfterTyper && pt != defn.ImplicitScrutineeTypeRef)
607-
constrainPatternType(tpt1.tpe, pt, termPattern = true)(ctx.addMode(Mode.GADTflexible))
607+
constrainPatternType(tpt1.tpe, pt)(ctx.addMode(Mode.GADTflexible))
608608
// special case for an abstract type that comes with a class tag
609609
tryWithClassTag(ascription(tpt1, isWildcard = true), pt)
610610
}
@@ -1103,8 +1103,6 @@ class Typer extends Namer
11031103
def typedTypeCase(cdef: untpd.CaseDef, selType: Type, pt: Type)(implicit ctx: Context): CaseDef = {
11041104
def caseRest(implicit ctx: Context) = {
11051105
val pat1 = checkSimpleKinded(typedType(cdef.pat)(ctx.addMode(Mode.Pattern)))
1106-
if (!ctx.isAfterTyper)
1107-
constrainPatternType(pat1.tpe, selType, termPattern = false)(ctx.addMode(Mode.GADTflexible))
11081106
val pat2 = indexPattern(cdef).transform(pat1)
11091107
val body1 = typedType(cdef.body, pt)
11101108
assignType(cpy.CaseDef(cdef)(pat2, EmptyTree, body1), pat2, body1)

0 commit comments

Comments
 (0)