Skip to content

Commit 4830901

Browse files
authored
Merge pull request #1769 from dotty-staging/fix-#1751
Fix #1751: Make dominator work after erasure
2 parents ac160ea + 306c312 commit 4830901

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
197197
case c :: rest =>
198198
val accu1 = if (accu exists (_ derivesFrom c)) accu else c :: accu
199199
if (cs == c.baseClasses) accu1 else dominators(rest, accu1)
200+
case Nil => // this case can happen because after erasure we do not have a top class anymore
201+
assert(ctx.erasedTypes)
202+
defn.ObjectClass :: Nil
200203
}
201204

202205
def mergeRefined(tp1: Type, tp2: Type): Type = {

tests/pos/i1751.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
trait Break { protected val break: Int; }
2+
case class BreakImpl(protected val break: Int) extends Break {}
3+
object Test {
4+
def f2(x: Break) = x match {
5+
case BreakImpl(x) => BreakImpl
6+
case _ => -1
7+
}
8+
def f4(x: Any) = x match {
9+
case BreakImpl(x) => x
10+
case _ => -1
11+
}
12+
def main(args: Array[String]): Unit = {
13+
val break = BreakImpl(22)
14+
assert(f2(break) == 22)
15+
assert(f4(break) == 22)
16+
}
17+
}

0 commit comments

Comments
 (0)