Skip to content

Commit 15cece6

Browse files
Merge pull request #7214 from dotty-staging/fix-6697
Fix #6697: Ingore bounds checks in match type patterns
2 parents 4d01d86 + 79e232d commit 15cece6

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
@@ -303,6 +303,15 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
303303
// case x: Tree[?]
304304
// (which translates to)
305305
// case x: (_: Tree[?])
306+
case m @ MatchTypeTree(bounds, selector, cases) =>
307+
// Analog to the case above for match types
308+
def tranformIgnoringBoundsCheck(x: CaseDef): CaseDef =
309+
super.transform(x)(ctx.addMode(Mode.Pattern)).asInstanceOf[CaseDef]
310+
cpy.MatchTypeTree(tree)(
311+
super.transform(bounds),
312+
super.transform(selector),
313+
cases.mapConserve(tranformIgnoringBoundsCheck)
314+
)
306315
case tree =>
307316
super.transform(tree)
308317
}

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)