From e46ed94b2f26b1e76f0c89877ea4a3a61476fcbc Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Thu, 13 Oct 2022 15:49:27 +0100 Subject: [PATCH] Fix redundancy (unreachability) warning --- .../dotty/tools/dotc/transform/patmat/Space.scala | 3 +-- tests/pos/i16123.scala | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i16123.scala diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index a8432833d42a..ca0e149f881f 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -534,16 +534,15 @@ class SpaceEngine(using Context) extends SpaceLogic { val mt: MethodType = unapp.widen match { case mt: MethodType => mt case pt: PolyType => - inContext(ctx.fresh.setExploreTyperState()) { val tvars = pt.paramInfos.map(newTypeVar(_)) val mt = pt.instantiate(tvars).asInstanceOf[MethodType] scrutineeTp <:< mt.paramInfos(0) // force type inference to infer a narrower type: could be singleton // see tests/patmat/i4227.scala mt.paramInfos(0) <:< scrutineeTp + instantiateSelected(mt, tvars) isFullyDefined(mt, ForceDegree.all) mt - } } // Case unapply: diff --git a/tests/pos/i16123.scala b/tests/pos/i16123.scala new file mode 100644 index 000000000000..2cba8f6dc96f --- /dev/null +++ b/tests/pos/i16123.scala @@ -0,0 +1,12 @@ +// scalac: -Werror +sealed trait Nat +case class Zero() extends Nat +case class Succ[N <: Nat](n: N) extends Nat + +class Test: + def foo(n: Nat): Int = n match + case Zero() => 0 + case Succ(Zero()) => 1 + case _ => 2 // was: warning for this line + + def test = foo(Succ(Succ(Zero()))) // evaluates to 2