Skip to content

Commit ad49770

Browse files
committed
Fix #6255: Don't check exhaustivity for Expr[T]
This seems to be the best strategy for now, given that the implicit args trick is only used for matching Expr[T], and `case _ =>` is always used in such cases. Otherwise, we will need to reason equality of Terms, which is subtle.
1 parent 574fd0c commit ad49770

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,15 +669,14 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
669669
!tp.hasAnnotation(defn.UncheckedAnnot) && {
670670
val tpw = tp.widen.dealias
671671
ctx.settings.YcheckAllPatmat.value ||
672-
tpw.typeSymbol.is(Sealed) ||
672+
tpw.typeSymbol.is(Sealed) && !tpw.isRef(defn.QuotedExprClass) ||
673673
tpw.isInstanceOf[OrType] ||
674674
(tpw.isInstanceOf[AndType] && {
675675
val and = tpw.asInstanceOf[AndType]
676676
isCheckable(and.tp1) || isCheckable(and.tp2)
677677
}) ||
678678
tpw.isRef(defn.BooleanClass) ||
679679
tpw.typeSymbol.is(JavaEnum) ||
680-
canDecompose(tpw) ||
681680
(defn.isTupleType(tpw) && tpw.argInfos.exists(isCheckable(_)))
682681
}
683682

@@ -719,7 +718,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
719718
}
720719

721720
private def redundancyCheckable(sel: Tree): Boolean =
722-
!sel.tpe.hasAnnotation(defn.UncheckedAnnot)
721+
!sel.tpe.hasAnnotation(defn.UncheckedAnnot) && !sel.tpe.widen.isRef(defn.QuotedExprClass)
723722

724723
def checkRedundancy(_match: Match): Unit = {
725724
val Match(sel, cases) = _match

tests/pos/i6255.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Foo {
2+
def foo(x: quoted.Expr[Int]) given scala.tasty.Reflection: Unit = x match {
3+
case '{ 1 } =>
4+
case '{ 2 } =>
5+
case _ =>
6+
}
7+
}

0 commit comments

Comments
 (0)