Skip to content

Commit f745041

Browse files
Fix #6697: Ingore bounds checks in match type pat
Similarly to what's done for values when we write `case _: F[x]`, there is no need to check that `x` conforms to its bounds as we are currently binding it.
1 parent fcbe885 commit f745041

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,15 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
306306
// case x: Tree[?]
307307
// (which translates to)
308308
// case x: (_: Tree[?])
309+
case m @ MatchTypeTree(bounds, selector, cases) =>
310+
// Analog to the case above for match types
311+
def ignoreBoundsCheck(x: CaseDef): CaseDef =
312+
super.transform(x)(ctx.addMode(Mode.Pattern)).asInstanceOf[CaseDef]
313+
cpy.MatchTypeTree(tree)(
314+
super.transform(bounds),
315+
super.transform(selector),
316+
cases.mapConserve(ignoreBoundsCheck)
317+
)
309318
case tree =>
310319
super.transform(tree)
311320
}

tests/pos/6697.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
sealed trait Off
3+
case class Of[sup, sub <: sup]() extends Off
4+
type Sup[O <: Off] = O match { case Of[sup, sub] => sup }
5+
type Sub[O <: Off] = O match { case Of[sup, sub] => sub }
6+
type Copy[O <: Off] = Of[Sup[O], Sub[O]]
7+
}

0 commit comments

Comments
 (0)