@@ -3,7 +3,7 @@ package dotc
3
3
package typer
4
4
5
5
import core ._
6
- import ast ._
6
+ import ast .{ tpd , _ }
7
7
import Trees ._
8
8
import Constants ._
9
9
import StdNames ._
@@ -28,15 +28,17 @@ import EtaExpansion.etaExpand
28
28
import dotty .tools .dotc .transform .Erasure .Boxing
29
29
import util .Positions ._
30
30
import util .common ._
31
- import util .{SourcePosition , Property }
31
+ import util .{Property , SourcePosition }
32
+
32
33
import collection .mutable
33
34
import annotation .tailrec
34
35
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 }
37
38
import rewrite .Rewrites .patch
38
39
import NavigateAST ._
39
40
import transform .SymUtils ._
41
+
40
42
import language .implicitConversions
41
43
import printing .SyntaxHighlighting ._
42
44
@@ -2126,17 +2128,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
2126
2128
typed(untpd.Select (untpd.TypedSplice (tree), nme.apply), pt)
2127
2129
}
2128
2130
else if (ctx.mode is Mode .Pattern ) {
2129
- tree match {
2130
- case _ : RefTree | _ : Literal
2131
- if ! isVarPattern(tree) &&
2132
- ! (tree.tpe <:< pt)(ctx.addMode(Mode .GADTflexible )) =>
2133
- val cmp =
2134
- untpd.Apply (
2135
- untpd.Select (untpd.TypedSplice (tree), nme.EQ ),
2136
- untpd.TypedSplice (dummyTreeOfType(pt)))
2137
- typedExpr(cmp, defn.BooleanType )(ctx.retractMode(Mode .Pattern ))
2138
- case _ =>
2139
- }
2131
+ checkEqualityEvidence(tree, pt)
2140
2132
tree
2141
2133
}
2142
2134
else if (tree.tpe <:< pt) {
@@ -2289,4 +2281,24 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
2289
2281
}
2290
2282
}
2291
2283
}
2284
+
2285
+ /** Check that `tree == x: pt` is typeable. Used when checking a pattern
2286
+ * against a selector of type `pt`. This implementation accounts for
2287
+ * user-defined definitions of `==`.
2288
+ *
2289
+ * Overwritten to no-op in ReTyper.
2290
+ */
2291
+ protected def checkEqualityEvidence (tree : tpd.Tree , pt : Type )(implicit ctx : Context ) : Unit = {
2292
+ tree match {
2293
+ case _ : RefTree | _ : Literal
2294
+ if ! isVarPattern(tree) &&
2295
+ ! (tree.tpe <:< pt) (ctx.addMode(Mode .GADTflexible )) =>
2296
+ val cmp =
2297
+ untpd.Apply (
2298
+ untpd.Select (untpd.TypedSplice (tree), nme.EQ ),
2299
+ untpd.TypedSplice (dummyTreeOfType(pt)))
2300
+ typedExpr(cmp, defn.BooleanType )
2301
+ case _ =>
2302
+ }
2303
+ }
2292
2304
}
0 commit comments