@@ -205,7 +205,9 @@ object TypeErasure {
205
205
}
206
206
207
207
/** The erased least upper bound is computed as follows
208
- * - if both argument are arrays, an array of the lub of the element types
208
+ * - if both argument are arrays of objects, an array of the lub of the element types
209
+ * - if both arguments are arrays of same primitives, an array of this primitive
210
+ * - if one argument is array of primitives and the other is array of objects, Object
209
211
* - if one argument is an array, Object
210
212
* - otherwise a common superclass or trait S of the argument classes, with the
211
213
* following two properties:
@@ -217,8 +219,14 @@ object TypeErasure {
217
219
*/
218
220
def erasedLub (tp1 : Type , tp2 : Type )(implicit ctx : Context ): Type = tp1 match {
219
221
case JavaArrayType (elem1) =>
222
+ import dotty .tools .dotc .transform .TypeUtils ._
220
223
tp2 match {
221
- case JavaArrayType (elem2) => JavaArrayType (erasedLub(elem1, elem2))
224
+ case JavaArrayType (elem2) =>
225
+ if (elem1.isPrimitiveValueType || elem2.isPrimitiveValueType) {
226
+ if (elem1.classSymbol eq elem2.classSymbol) // same primitive
227
+ JavaArrayType (elem1)
228
+ else defn.ObjectType
229
+ } else JavaArrayType (erasedLub(elem1, elem2))
222
230
case _ => defn.ObjectType
223
231
}
224
232
case _ =>
0 commit comments