Skip to content

Commit d5a6d4f

Browse files
committed
Fix exhaustivity due to separate TypeVar lambdas
1 parent 1637282 commit d5a6d4f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,8 @@ object SpaceEngine {
476476
erase(parent, inArray, isValue, isTyped)
477477

478478
case tref: TypeRef if tref.symbol.isPatternBound =>
479-
if inArray then tref.underlying
480-
else if isValue then tref.superType
479+
if inArray then erase(tref.underlying, inArray, isValue, isTyped)
480+
else if isValue then erase(tref.superType, inArray, isValue, isTyped)
481481
else WildcardType
482482

483483
case _ => tp
@@ -531,7 +531,7 @@ object SpaceEngine {
531531
val mt: MethodType = unapp.widen match {
532532
case mt: MethodType => mt
533533
case pt: PolyType =>
534-
val tvars = pt.paramInfos.map(newTypeVar(_))
534+
val tvars = constrained(pt, EmptyTree)._2.tpes
535535
val mt = pt.instantiate(tvars).asInstanceOf[MethodType]
536536
scrutineeTp <:< mt.paramInfos(0)
537537
// force type inference to infer a narrower type: could be singleton

tests/pos/i14224.1.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//> using options -Werror
2+
3+
// Derived from the extensive test in the gist in i14224
4+
// Minimising to the false positive in SealedTrait1.either
5+
6+
sealed trait Foo[A, A1 <: A]
7+
final case class Bar[A, A1 <: A](value: A1) extends Foo[A, A1]
8+
9+
class Main:
10+
def test[A, A1 <: A](foo: Foo[A, A1]): A1 = foo match
11+
case Bar(v) => v

0 commit comments

Comments
 (0)