aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorodersky <odersky@gmail.com>2016-02-08 17:17:21 +0100
committerodersky <odersky@gmail.com>2016-02-08 17:17:21 +0100
commit0c4eb3305b0adf82f779f6e88bb01f7274ce00b9 (patch)
treed685173b89ef38ee883aa42bb9f544d0129e6dc5
parent8aeee17d2b6f24a0c3cc21f858ff60bc47ab2dc1 (diff)
parente384b3af6859c7e2d8481288e293ee9d86a377b9 (diff)
downloaddotty-0c4eb3305b0adf82f779f6e88bb01f7274ce00b9.tar.gz
dotty-0c4eb3305b0adf82f779f6e88bb01f7274ce00b9.tar.bz2
dotty-0c4eb3305b0adf82f779f6e88bb01f7274ce00b9.zip
Merge pull request #1067 from dotty-staging/fix-1065
Fix #1065 erasedLub for arrays of primitives.
-rw-r--r--src/dotty/tools/dotc/core/TypeErasure.scala12
-rw-r--r--tests/pos/erasure-array.scala12
2 files changed, 22 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/core/TypeErasure.scala b/src/dotty/tools/dotc/core/TypeErasure.scala
index e4f91914b..26cac4f72 100644
--- a/src/dotty/tools/dotc/core/TypeErasure.scala
+++ b/src/dotty/tools/dotc/core/TypeErasure.scala
@@ -205,7 +205,9 @@ object TypeErasure {
}
/** The erased least upper bound is computed as follows
- * - if both argument are arrays, an array of the lub of the element types
+ * - if both argument are arrays of objects, an array of the lub of the element types
+ * - if both arguments are arrays of same primitives, an array of this primitive
+ * - if one argument is array of primitives and the other is array of objects, Object
* - if one argument is an array, Object
* - otherwise a common superclass or trait S of the argument classes, with the
* following two properties:
@@ -217,8 +219,14 @@ object TypeErasure {
*/
def erasedLub(tp1: Type, tp2: Type)(implicit ctx: Context): Type = tp1 match {
case JavaArrayType(elem1) =>
+ import dotty.tools.dotc.transform.TypeUtils._
tp2 match {
- case JavaArrayType(elem2) => JavaArrayType(erasedLub(elem1, elem2))
+ case JavaArrayType(elem2) =>
+ if (elem1.isPrimitiveValueType || elem2.isPrimitiveValueType) {
+ if (elem1.classSymbol eq elem2.classSymbol) // same primitive
+ JavaArrayType(elem1)
+ else defn.ObjectType
+ } else JavaArrayType(erasedLub(elem1, elem2))
case _ => defn.ObjectType
}
case _ =>
diff --git a/tests/pos/erasure-array.scala b/tests/pos/erasure-array.scala
new file mode 100644
index 000000000..63240e980
--- /dev/null
+++ b/tests/pos/erasure-array.scala
@@ -0,0 +1,12 @@
+// https://github.com/lampepfl/dotty/issues/1065
+package hello
+
+object world {
+ def mkArray(atype: Int): Array[_ <: AnyVal] = {
+ (if (atype == 1) new Array[Int](10) else new Array[Float](10))
+ }
+
+ def main(args: Array[String]): Unit = {
+ println(mkArray(1))
+ }
+}