Skip to content

Commit 7953479

Browse files
committed
Make pattern matching typecheck more principled
When checking a pattern `p` against a selector `s` we should check that `p == s` is typable. So far we did this in a roundabout way by calling homogenizeType and canCheckEquals diretcly. But that is correct only if there are no user-defined definitions of `==`.
1 parent 23e64a3 commit 7953479

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,8 +2098,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
20982098
case _: RefTree | _: Literal
20992099
if !isVarPattern(tree) &&
21002100
!(tree.tpe <:< pt)(ctx.addMode(Mode.GADTflexible)) =>
2101-
val tp1 :: tp2 :: Nil = harmonizeTypes(pt :: wtp :: Nil)
2102-
checkCanEqual(tp1, tp2, tree.pos)(ctx.retractMode(Mode.Pattern))
2101+
val cmp =
2102+
untpd.Apply(
2103+
untpd.Select(untpd.TypedSplice(tree), nme.EQ),
2104+
untpd.TypedSplice(dummyTreeOfType(pt)))
2105+
typedExpr(cmp, defn.BooleanType)(ctx.retractMode(Mode.Pattern))
21032106
case _ =>
21042107
}
21052108
tree

0 commit comments

Comments
 (0)