Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions tests/pos/i16123.scala
Original file line number Diff line number Diff line change
@@ -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