Skip to content

Commit 68f7a25

Browse files
committed
Deskolemise patterns to suppress exhaustivity warnings
Ideally I'd want to not be destructive with this widen, but it seems to already being done on the other side: in `signature` where the components of the unapply result type are obtained the call to: mt.instantiate(scrutineeTp :: Nil).finalResultType removes the more precise `blub.type` that was present in the signature. So now, by widening the pattern the spaces cancel each other out, thus the match is deemed exhaustive.
1 parent ec15557 commit 68f7a25

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,8 @@ class SpaceEngine(using Context) extends SpaceLogic {
354354
case pat: Ident if isBackquoted(pat) =>
355355
Typ(pat.tpe, decomposed = false)
356356

357-
case Ident(nme.WILDCARD) =>
358-
Typ(erase(pat.tpe.stripAnnots, isValue = true), decomposed = false)
359-
360357
case Ident(_) | Select(_, _) =>
361-
Typ(erase(pat.tpe.stripAnnots, isValue = true), decomposed = false)
358+
Typ(erase(pat.tpe.stripAnnots.widenSkolem, isValue = true), decomposed = false)
362359

363360
case Alternative(trees) =>
364361
Or(trees.map(project(_)))

tests/patmat/i13110.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
object Test {
2+
sealed trait Base
3+
class Blub extends Base
4+
object Blub {
5+
def unapply(blub: Blub): Some[(Int, blub.type)] =
6+
Some(1 -> blub)
7+
}
8+
9+
(null: Base) match {
10+
case Blub(i, x) => println(i)
11+
}
12+
}

0 commit comments

Comments
 (0)