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 =>
227227 /** Translate a repeated type T* to an `Array[? <: Upper]`
228228 * such that it is compatible with java varargs.
229229 *
230- * If T is not a primitive type, we set `Upper = T & AnyRef`
230+ * When necessary we set `Upper = T & AnyRef`
231231 * to prevent the erasure of `Array[? <: Upper]` to Object,
232232 * which would break the varargs from Java.
233233 */
234234 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
240237
238+ if element <:< defn.AnyRefType || element.typeSymbol.isPrimitiveValueClass then array
239+ else defn.ArrayOf (TypeBounds .upper(AndType (element, defn.AnyRefType ))) // Array[? <: T & AnyRef]
241240}
Original file line number Diff line number Diff line change @@ -186,10 +186,11 @@ object GenericSignatures {
186186 case defn.ArrayOf (elemtp) =>
187187 if (isUnboundedGeneric(elemtp))
188188 jsig(defn.ObjectType )
189- else {
189+ else
190190 builder.append(ClassfileConstants .ARRAY_TAG )
191- jsig(elemtp)
192- }
191+ elemtp match
192+ case TypeBounds (lo, hi) => jsig(hi.widenDealias)
193+ case _ => jsig(elemtp)
193194
194195 case RefOrAppliedType (sym, pre, args) =>
195196 if (sym == defn.PairClass && tp.tupleArity > Definitions .MaxTupleArity )
You can’t perform that action at this time.
0 commit comments