Skip to content

Commit

Permalink
Fix scala#6697: Ingore bounds checks in match type pat
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
OlivierBlanvillain committed Sep 27, 2019
1 parent 71234eb commit 79e232d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,15 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
// case x: Tree[?]
// (which translates to)
// case x: (_: Tree[?])
case m @ MatchTypeTree(bounds, selector, cases) =>
// Analog to the case above for match types
def tranformIgnoringBoundsCheck(x: CaseDef): CaseDef =
super.transform(x)(ctx.addMode(Mode.Pattern)).asInstanceOf[CaseDef]
cpy.MatchTypeTree(tree)(
super.transform(bounds),
super.transform(selector),
cases.mapConserve(tranformIgnoringBoundsCheck)
)
case tree =>
super.transform(tree)
}
Expand Down
7 changes: 7 additions & 0 deletions tests/pos/6697.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object Test {
sealed trait Off
case class Of[sup, sub <: sup]() extends Off
type Sup[O <: Off] = O match { case Of[sup, sub] => sup }
type Sub[O <: Off] = O match { case Of[sup, sub] => sub }
type Copy[O <: Off] = Of[Sup[O], Sub[O]]
}

0 comments on commit 79e232d

Please sign in to comment.