Skip to content

Commit d9301e0

Browse files
Fix redundancy (unreachability) warning (#16179)
2 parents 91b76c3 + e46ed94 commit d9301e0

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -534,16 +534,15 @@ class SpaceEngine(using Context) extends SpaceLogic {
534534
val mt: MethodType = unapp.widen match {
535535
case mt: MethodType => mt
536536
case pt: PolyType =>
537-
inContext(ctx.fresh.setExploreTyperState()) {
538537
val tvars = pt.paramInfos.map(newTypeVar(_))
539538
val mt = pt.instantiate(tvars).asInstanceOf[MethodType]
540539
scrutineeTp <:< mt.paramInfos(0)
541540
// force type inference to infer a narrower type: could be singleton
542541
// see tests/patmat/i4227.scala
543542
mt.paramInfos(0) <:< scrutineeTp
543+
instantiateSelected(mt, tvars)
544544
isFullyDefined(mt, ForceDegree.all)
545545
mt
546-
}
547546
}
548547

549548
// Case unapply:

tests/pos/i16123.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// scalac: -Werror
2+
sealed trait Nat
3+
case class Zero() extends Nat
4+
case class Succ[N <: Nat](n: N) extends Nat
5+
6+
class Test:
7+
def foo(n: Nat): Int = n match
8+
case Zero() => 0
9+
case Succ(Zero()) => 1
10+
case _ => 2 // was: warning for this line
11+
12+
def test = foo(Succ(Succ(Zero()))) // evaluates to 2

0 commit comments

Comments
 (0)