From 306c31214b8f729b810d1f162da20ff8ca6a2848 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 2 Dec 2016 18:37:28 +0100 Subject: [PATCH] Fix #1751: Make dominator work after erasure i1751.scala shows a case where we need to compute the approximation of an or-type during erasure. This can lead to an empty set of common classes because Any does not exist anymore after erasure. --- .../src/dotty/tools/dotc/core/TypeOps.scala | 3 +++ tests/pos/i1751.scala | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/pos/i1751.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index 92e5f9d5754b..39214dd0c7b0 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -197,6 +197,9 @@ trait TypeOps { this: Context => // TODO: Make standalone object. case c :: rest => val accu1 = if (accu exists (_ derivesFrom c)) accu else c :: accu if (cs == c.baseClasses) accu1 else dominators(rest, accu1) + case Nil => // this case can happen because after erasure we do not have a top class anymore + assert(ctx.erasedTypes) + defn.ObjectClass :: Nil } def mergeRefined(tp1: Type, tp2: Type): Type = { diff --git a/tests/pos/i1751.scala b/tests/pos/i1751.scala new file mode 100644 index 000000000000..d51cdc65dbf5 --- /dev/null +++ b/tests/pos/i1751.scala @@ -0,0 +1,17 @@ +trait Break { protected val break: Int; } +case class BreakImpl(protected val break: Int) extends Break {} +object Test { + def f2(x: Break) = x match { + case BreakImpl(x) => BreakImpl + case _ => -1 + } + def f4(x: Any) = x match { + case BreakImpl(x) => x + case _ => -1 + } + def main(args: Array[String]): Unit = { + val break = BreakImpl(22) + assert(f2(break) == 22) + assert(f4(break) == 22) + } +}