From 7a28abdf2bedf90d8e43f891c39ad7ceafe0e7bb Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Tue, 11 May 2021 18:02:16 +0200 Subject: [PATCH] Fix #12408: Parameterized classes should be applied for prefix inference --- .../src/dotty/tools/dotc/core/TypeOps.scala | 3 ++- tests/patmat/i12408.check | 2 ++ tests/patmat/i12408.scala | 24 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/patmat/i12408.check create mode 100644 tests/patmat/i12408.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index ac0b52b51972..a842c5e58261 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -769,7 +769,8 @@ object TypeOps: this(tref) else { prefixTVar = WildcardType // prevent recursive call from assigning it - prefixTVar = newTypeVar(TypeBounds.upper(this(tref))) + val tref2 = this(tref.applyIfParameterized(tref.typeParams.map(_ => TypeBounds.empty))) + prefixTVar = newTypeVar(TypeBounds.upper(tref2)) prefixTVar } case tp => mapOver(tp) diff --git a/tests/patmat/i12408.check b/tests/patmat/i12408.check new file mode 100644 index 000000000000..60acc2cba84e --- /dev/null +++ b/tests/patmat/i12408.check @@ -0,0 +1,2 @@ +13: Pattern Match Exhaustivity: A(_), C(_) +21: Pattern Match diff --git a/tests/patmat/i12408.scala b/tests/patmat/i12408.scala new file mode 100644 index 000000000000..442e723cb195 --- /dev/null +++ b/tests/patmat/i12408.scala @@ -0,0 +1,24 @@ +class X[T] { + sealed trait P + + case class A(id: Long) extends P + case class B(id: Long, x: Long) extends P + case class C(id: Long) extends P + + def m(p: P): Unit = p match { + case B(_, x) => + case _ => + } + + def n(p: P): Unit = p match { + case B(_, x) => + } + + def o(p: P): Unit = p match { + case A(_) => + case B(_, x) => + case C(_) => + case _ => + } + +}