Skip to content

Commit e41bf9a

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 45fbf3e commit e41bf9a

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
@@ -2650,7 +2650,8 @@ class Typer extends Namer
26502650
tree match {
26512651
case _: RefTree | _: Literal
26522652
if !isVarPattern(tree) &&
2653-
!(tree.tpe <:< pt) (ctx.addMode(Mode.GADTflexible)) =>
2653+
!(pt <:< tree.tpe) &&
2654+
!(tree.tpe <:< pt)(ctx.addMode(Mode.GADTflexible)) =>
26542655
val cmp =
26552656
untpd.Apply(
26562657
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)