From 68f7a251f2c4c5d17c90f5c639b760470000f280 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 23 Jul 2021 12:24:56 +0100 Subject: [PATCH] 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. --- .../dotty/tools/dotc/transform/patmat/Space.scala | 5 +---- tests/patmat/i13110.scala | 12 ++++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 tests/patmat/i13110.scala diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index af02bfed8411..708944434015 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -354,11 +354,8 @@ class SpaceEngine(using Context) extends SpaceLogic { case pat: Ident if isBackquoted(pat) => Typ(pat.tpe, decomposed = false) - case Ident(nme.WILDCARD) => - Typ(erase(pat.tpe.stripAnnots, isValue = true), decomposed = false) - case Ident(_) | Select(_, _) => - Typ(erase(pat.tpe.stripAnnots, isValue = true), decomposed = false) + Typ(erase(pat.tpe.stripAnnots.widenSkolem, isValue = true), decomposed = false) case Alternative(trees) => Or(trees.map(project(_))) diff --git a/tests/patmat/i13110.scala b/tests/patmat/i13110.scala new file mode 100644 index 000000000000..e5a143a948a9 --- /dev/null +++ b/tests/patmat/i13110.scala @@ -0,0 +1,12 @@ +object Test { + sealed trait Base + class Blub extends Base + object Blub { + def unapply(blub: Blub): Some[(Int, blub.type)] = + Some(1 -> blub) + } + + (null: Base) match { + case Blub(i, x) => println(i) + } +}