diff options
-rw-r--r-- | src/dotty/tools/dotc/core/TypeErasure.scala | 6 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Applications.scala | 2 | ||||
-rw-r--r-- | tests/run/OrType.scala | 11 |
3 files changed, 17 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/core/TypeErasure.scala b/src/dotty/tools/dotc/core/TypeErasure.scala index 0ef31015c..f27b2fd1e 100644 --- a/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/src/dotty/tools/dotc/core/TypeErasure.scala @@ -234,7 +234,11 @@ object TypeErasure { case nil => bestSoFar } - loop(tp1.baseClasses, defn.ObjectClass).typeRef + val t = loop(tp1.baseClasses, defn.ObjectClass) + if (t eq defn.AnyValClass) + // while AnyVal is a valid common super class for primitives it does not exist after erasure + defn.ObjectType + else t.typeRef } } diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index c45db4ccc..40029c42b 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -1117,7 +1117,7 @@ trait Applications extends Compatibility { self: Typer => case cdef: CaseDef => tpd.cpy.CaseDef(cdef)(body = adapt(cdef.body, pt)) case _ => adaptInterpolated(tree, pt, tree) } - harmonizeWith(trees)(_.tpe, adapt) + if (ctx.isAfterTyper) trees else harmonizeWith(trees)(_.tpe, adapt) } /** If all `types` are numeric value types, and they are not all the same type, diff --git a/tests/run/OrType.scala b/tests/run/OrType.scala new file mode 100644 index 000000000..9ab805def --- /dev/null +++ b/tests/run/OrType.scala @@ -0,0 +1,11 @@ +class B(val x: Int) +class C(val x: Double) + +object Test{ + def bar(x: B | C): Int | Double = x.x + def main(args: Array[String]): Unit = { + val b = new B(1) + val c = new C(1) + bar(if (b.hashCode > c.hashCode) b else c) + } +} |