File tree Expand file tree Collapse file tree 2 files changed +9
-9
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 2 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -227,15 +227,14 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
227
227
/** Translate a repeated type T* to an `Array[? <: Upper]`
228
228
* such that it is compatible with java varargs.
229
229
*
230
- * If T is not a primitive type, we set `Upper = T & AnyRef`
230
+ * When necessary we set `Upper = T & AnyRef`
231
231
* to prevent the erasure of `Array[? <: Upper]` to Object,
232
232
* which would break the varargs from Java.
233
233
*/
234
234
private def varargArrayType (tp : Type )(using Context ): Type =
235
- val array = tp.translateFromRepeated(toArray = true )
236
- val element = array.elemType.typeSymbol
237
-
238
- if element.isPrimitiveValueClass then array
239
- else defn.ArrayOf (TypeBounds .upper(AndType (element.typeRef, defn.AnyRefType )))
235
+ val array = tp.translateFromRepeated(toArray = true ) // Array[? <: T]
236
+ val element = array.elemType.hiBound // T
240
237
238
+ if element <:< defn.AnyRefType || element.typeSymbol.isPrimitiveValueClass then array
239
+ else defn.ArrayOf (TypeBounds .upper(AndType (element, defn.AnyRefType ))) // Array[? <: T & AnyRef]
241
240
}
Original file line number Diff line number Diff line change @@ -186,10 +186,11 @@ object GenericSignatures {
186
186
case defn.ArrayOf (elemtp) =>
187
187
if (isUnboundedGeneric(elemtp))
188
188
jsig(defn.ObjectType )
189
- else {
189
+ else
190
190
builder.append(ClassfileConstants .ARRAY_TAG )
191
- jsig(elemtp)
192
- }
191
+ elemtp match
192
+ case TypeBounds (lo, hi) => jsig(hi.widenDealias)
193
+ case _ => jsig(elemtp)
193
194
194
195
case RefOrAppliedType (sym, pre, args) =>
195
196
if (sym == defn.PairClass && tp.tupleArity > Definitions .MaxTupleArity )
You can’t perform that action at this time.
0 commit comments