Skip to content

Commit c5acd99

Browse files
committed
Extract check to a protected method on Typer and override with an empty one on ReTyper
1 parent c938deb commit c5acd99

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,6 @@ class ReTyper extends Typer {
104104
Implicits.NoImplicitMatches
105105
override def checkCanEqual(ltp: Type, rtp: Type, pos: Position)(implicit ctx: Context): Unit = ()
106106
override def inlineExpansion(mdef: DefDef)(implicit ctx: Context): List[Tree] = mdef :: Nil
107+
108+
override protected def checkEqualityEvidence(tree: tpd.Tree, pt: Type)(implicit ctx: Context): Unit = ()
107109
}

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotc
33
package typer
44

55
import core._
6-
import ast._
6+
import ast.{tpd, _}
77
import Trees._
88
import Constants._
99
import StdNames._
@@ -28,15 +28,17 @@ import EtaExpansion.etaExpand
2828
import dotty.tools.dotc.transform.Erasure.Boxing
2929
import util.Positions._
3030
import util.common._
31-
import util.{SourcePosition, Property}
31+
import util.{Property, SourcePosition}
32+
3233
import collection.mutable
3334
import annotation.tailrec
3435
import Implicits._
35-
import util.Stats.{track, record}
36-
import config.Printers.{typr, gadts}
36+
import util.Stats.{record, track}
37+
import config.Printers.{gadts, typr}
3738
import rewrite.Rewrites.patch
3839
import NavigateAST._
3940
import transform.SymUtils._
41+
4042
import language.implicitConversions
4143
import printing.SyntaxHighlighting._
4244

@@ -2122,18 +2124,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
21222124
typed(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt)
21232125
}
21242126
else if (ctx.mode is Mode.Pattern) {
2125-
tree match {
2126-
case _: RefTree | _: Literal
2127-
if !isVarPattern(tree) &&
2128-
!(tree.tpe <:< pt)(ctx.addMode(Mode.GADTflexible)) &&
2129-
!this.isInstanceOf[ReTyper] =>
2130-
val cmp =
2131-
untpd.Apply(
2132-
untpd.Select(untpd.TypedSplice(tree), nme.EQ),
2133-
untpd.TypedSplice(dummyTreeOfType(pt)))
2134-
typedExpr(cmp, defn.BooleanType)(ctx.retractMode(Mode.Pattern))
2135-
case _ =>
2136-
}
2127+
checkEqualityEvidence(tree, pt)
21372128
tree
21382129
}
21392130
else if (tree.tpe <:< pt) {
@@ -2278,4 +2269,18 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
22782269
}
22792270
}
22802271
}
2272+
2273+
protected def checkEqualityEvidence(tree: tpd.Tree, pt: Type)(implicit ctx: Context) : Unit = {
2274+
tree match {
2275+
case _: RefTree | _: Literal
2276+
if !isVarPattern(tree) &&
2277+
!(tree.tpe <:< pt) (ctx.addMode(Mode.GADTflexible)) =>
2278+
val cmp =
2279+
untpd.Apply(
2280+
untpd.Select(untpd.TypedSplice(tree), nme.EQ),
2281+
untpd.TypedSplice(dummyTreeOfType(pt)))
2282+
typedExpr(cmp, defn.BooleanType)(ctx.retractMode(Mode.Pattern))
2283+
case _ =>
2284+
}
2285+
}
22812286
}

0 commit comments

Comments
 (0)