Skip to content

Commit 30787e5

Browse files
committed
support option-less patmat as complete match
1 parent 20448c8 commit 30787e5

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
323323
import SpaceEngine._
324324
import tpd._
325325

326-
private val scalaSomeClass = ctx.requiredClassRef("scala.Some".toTermName).symbol.asClass
326+
private val scalaOptionClass = ctx.requiredClassRef("scala.Option".toTypeName).symbol.asClass
327327
private val scalaSeqFactoryClass = ctx.requiredClass("scala.collection.generic.SeqFactory".toTypeName)
328328
private val scalaListType = ctx.requiredClassRef("scala.collection.immutable.List".toTypeName)
329329
private val scalaNilType = ctx.requiredModuleRef("scala.collection.immutable.Nil".toTermName)
@@ -420,7 +420,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
420420
Kon(pat.tpe.stripAnnots, pats.map(pat => project(pat)))
421421
else if (fun.symbol.owner == scalaSeqFactoryClass && fun.symbol.name == nme.unapplySeq)
422422
projectList(pats)
423-
else if (fun.symbol.info.resultType.isRef(scalaSomeClass))
423+
else if (!fun.symbol.info.finalResultType.isRef(scalaOptionClass))
424424
Kon(pat.tpe.stripAnnots, pats.map(pat => project(pat)))
425425
else
426426
Fun(pat.tpe.stripAnnots, fun.tpe, pats.map(pat => project(pat)))

tests/patmat/optionless.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
28: Pattern Match Exhaustivity: _: Tree

tests/patmat/optionless.scala

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
sealed trait Tree
2+
case class Ident(name: String) extends Tree
3+
4+
object Ident1 {
5+
def unapply(tree: Tree): Ident = ???
6+
}
7+
8+
trait Cap
9+
object Ident2 {
10+
def unapply(tree: Tree)(implicit cap: Cap): Ident = ???
11+
}
12+
13+
object Ident3 {
14+
def unapply(tree: Tree)(implicit cap: Cap): Option[Ident] = ???
15+
}
16+
17+
18+
19+
class Test {
20+
def foo(t: Tree): Unit = t match {
21+
case Ident1(t) =>
22+
}
23+
24+
def bar(t: Tree)(implicit c: Cap): Unit = t match {
25+
case Ident2(t) =>
26+
}
27+
28+
def qux(t: Tree)(implicit c: Cap): Unit = t match {
29+
case Ident3(t) =>
30+
}
31+
32+
}

0 commit comments

Comments
 (0)