diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index e4e5dbcc85df..fe6e2f07f4fb 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1713,6 +1713,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer val pat1 = withMode(Mode.Pattern) { checkSimpleKinded(typedType(cdef.pat, mapPatternBounds = true)) } + if !ctx.isAfterTyper && pt != defn.ImplicitScrutineeTypeRef then + withMode(Mode.GadtConstraintInference) { + TypeComparer.constrainPatternType(pat1.tpe, selType) + } val pat2 = indexPattern(cdef).transform(pat1) var body1 = typedType(cdef.body, pt) if !body1.isType then diff --git a/tests/pos/i14151.scala b/tests/pos/i14151.scala new file mode 100644 index 000000000000..fbb124794595 --- /dev/null +++ b/tests/pos/i14151.scala @@ -0,0 +1,2 @@ +class BoundedPair[A, B <: A]: + type Second[A, T <: BoundedPair[A, _ <: A]] <: A = T match { case BoundedPair[A, b] => b } diff --git a/tests/pos/i14151b.scala b/tests/pos/i14151b.scala new file mode 100644 index 000000000000..f3f0e429ff79 --- /dev/null +++ b/tests/pos/i14151b.scala @@ -0,0 +1,2 @@ +class Single[B](val value: B): + type Retrieve[A, T <: Single[_ <: A]] <: A = T match { case Single[b] => b } diff --git a/tests/pos/i14151c.scala b/tests/pos/i14151c.scala new file mode 100644 index 000000000000..b138a3da3fd4 --- /dev/null +++ b/tests/pos/i14151c.scala @@ -0,0 +1,2 @@ +class Single[B](val value: B): + type Retrieve[A] <: A = Single[A] match { case Single[b] => b }