Skip to content

Commit 2e9cd7d

Browse files
committed
Survive bottom values in pattern matches
See test case. This caused two spurious overloding errors, one when looking for equality evidence and then again in the emit method of the pattern matcher. A spurious error was also eliminated in neg/ensureReported.scala.
1 parent 5c2a105 commit 2e9cd7d

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
824824

825825
/** `tree == that` */
826826
def equal(that: Tree)(implicit ctx: Context) =
827-
applyOverloaded(tree, nme.EQ, that :: Nil, Nil, defn.BooleanType)
827+
if (that.tpe.widen.isRef(defn.NothingClass))
828+
Literal(Constant(false))
829+
else
830+
applyOverloaded(tree, nme.EQ, that :: Nil, Nil, defn.BooleanType)
828831

829832
/** `tree.isInstanceOf[tp]`, with special treatment of singleton types */
830833
def isInstance(tp: Type)(implicit ctx: Context): Tree = tp.dealias match {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2653,7 +2653,8 @@ class Typer extends Namer
26532653
tree match {
26542654
case _: RefTree | _: Literal
26552655
if !isVarPattern(tree) &&
2656-
!(tree.tpe <:< pt) (ctx.addMode(Mode.GADTflexible)) =>
2656+
!(pt <:< tree.tpe) &&
2657+
!(tree.tpe <:< pt)(ctx.addMode(Mode.GADTflexible)) =>
26572658
val cmp =
26582659
untpd.Apply(
26592660
untpd.Select(untpd.TypedSplice(tree), nme.EQ),

tests/neg/NoneMatch.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
3+
None match {
4+
case Some(0) => ??? // error: unreachable
5+
}
6+
7+
}

tests/neg/ensureReported.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object AnonymousF {
22
val f = {
3-
case l @ List(1) => // error: missing parameter type // error: Ambiguous overload
3+
case l @ List(1) => // error: missing parameter type
44
Some(l)
55
}
66
}

0 commit comments

Comments
 (0)