Skip to content

Commit 0a746fb

Browse files
committed
Fix #4227: handle singleton types in exhaustivity check
1 parent 14187e2 commit 0a746fb

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,21 +400,21 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
400400

401401
val sig =
402402
if (isSyntheticScala2Unapply(unappSym) && caseAccessors.length == argLen)
403-
caseAccessors.map(_.info.asSeenFrom(mt.paramInfos.head, caseClass).widen)
403+
caseAccessors.map(_.info.asSeenFrom(mt.paramInfos.head, caseClass).widenExpr)
404404
else if (mt.finalResultType.isRef(defn.BooleanClass))
405405
List()
406406
else {
407407
val isUnapplySeq = unappSym.name == nme.unapplySeq
408408
if (isProductMatch(mt.finalResultType, argLen) && !isUnapplySeq) {
409409
productSelectors(mt.finalResultType).take(argLen)
410-
.map(_.info.asSeenFrom(mt.finalResultType, mt.resultType.classSymbol).widen)
410+
.map(_.info.asSeenFrom(mt.finalResultType, mt.resultType.classSymbol).widenExpr)
411411
}
412412
else {
413413
val resTp = mt.finalResultType.select(nme.get).finalResultType.widen
414414
if (isUnapplySeq) scalaListType.appliedTo(resTp.argTypes.head) :: Nil
415415
else if (argLen == 0) Nil
416416
else if (isProductMatch(resTp, argLen))
417-
productSelectors(resTp).map(_.info.asSeenFrom(resTp, resTp.classSymbol).widen)
417+
productSelectors(resTp).map(_.info.asSeenFrom(resTp, resTp.classSymbol).widenExpr)
418418
else resTp :: Nil
419419
}
420420
}

tests/patmat/i4227.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Test {
2+
def foo(x: Option[1]) = x match {
3+
case Some(1) =>
4+
case None =>
5+
}
6+
}

0 commit comments

Comments
 (0)