Skip to content

Commit 6bb6210

Browse files
committed
Merge pull request #798 from dotty-staging/fix-791
Fix 791
2 parents ec683c1 + 41b8853 commit 6bb6210

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,11 @@ object TypeErasure {
234234
case nil =>
235235
bestSoFar
236236
}
237-
loop(tp1.baseClasses, defn.ObjectClass).typeRef
237+
val t = loop(tp1.baseClasses, defn.ObjectClass)
238+
if (t eq defn.AnyValClass)
239+
// while AnyVal is a valid common super class for primitives it does not exist after erasure
240+
defn.ObjectType
241+
else t.typeRef
238242
}
239243
}
240244

src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ trait Applications extends Compatibility { self: Typer =>
11171117
case cdef: CaseDef => tpd.cpy.CaseDef(cdef)(body = adapt(cdef.body, pt))
11181118
case _ => adaptInterpolated(tree, pt, tree)
11191119
}
1120-
harmonizeWith(trees)(_.tpe, adapt)
1120+
if (ctx.isAfterTyper) trees else harmonizeWith(trees)(_.tpe, adapt)
11211121
}
11221122

11231123
/** If all `types` are numeric value types, and they are not all the same type,

tests/run/OrType.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class B(val x: Int)
2+
class C(val x: Double)
3+
4+
object Test{
5+
def bar(x: B | C): Int | Double = x.x
6+
def main(args: Array[String]): Unit = {
7+
val b = new B(1)
8+
val c = new C(1)
9+
bar(if (b.hashCode > c.hashCode) b else c)
10+
}
11+
}

0 commit comments

Comments
 (0)