@@ -378,7 +378,7 @@ class TypeApplications(val self: Type) extends AnyVal {
378
378
self.derivedExprType(tp.translateParameterized(from, to))
379
379
case _ =>
380
380
if (self.derivesFrom(from)) {
381
- def elemType (tp : Type ): Type = tp match
381
+ def elemType (tp : Type ): Type = tp.widenDealias match
382
382
case tp : AndOrType => tp.derivedAndOrType(elemType(tp.tp1), elemType(tp.tp2))
383
383
case _ => tp.baseType(from).argInfos.head
384
384
val arg = elemType(self)
@@ -388,18 +388,26 @@ class TypeApplications(val self: Type) extends AnyVal {
388
388
else self
389
389
}
390
390
391
- /** If this is repeated parameter type, its underlying Seq type,
392
- * or, if isJava is true, Array type, else the type itself.
391
+ /** If this is a repeated parameter `*T`, translate it to either `Seq[T]` or
392
+ * `Array[? <: T]` depending on the value of `toArray`.
393
+ * Additionally, if `translateWildcard` is true, a wildcard type
394
+ * will be translated to `*<?>`.
395
+ * Other types are kept as-is.
393
396
*/
394
- def underlyingIfRepeated (isJava : Boolean )(implicit ctx : Context ): Type =
395
- if (self.isRepeatedParam) {
396
- val seqClass = if (isJava) defn.ArrayClass else defn.SeqClass
397
- // If `isJava` is set, then we want to turn `RepeatedParam[T]` into `Array[? <: T]`,
398
- // since arrays aren't covariant until after erasure. See `tests/pos/i5140`.
399
- translateParameterized(defn.RepeatedParamClass , seqClass, wildcardArg = isJava)
400
- }
397
+ def translateFromRepeated (toArray : Boolean , translateWildcard : Boolean = false )(using Context ): Type =
398
+ val seqClass = if (toArray) defn.ArrayClass else defn.SeqClass
399
+ if translateWildcard && self.isInstanceOf [WildcardType ] then
400
+ seqClass.typeRef.appliedTo(WildcardType )
401
+ else if self.isRepeatedParam then
402
+ // We want `Array[? <: T]` because arrays aren't covariant until after
403
+ // erasure. See `tests/pos/i5140`.
404
+ translateParameterized(defn.RepeatedParamClass , seqClass, wildcardArg = toArray)
401
405
else self
402
406
407
+ /** Translate a `From[T]` into a `*T`. */
408
+ def translateToRepeated (from : ClassSymbol )(using Context ): Type =
409
+ translateParameterized(from, defn.RepeatedParamClass )
410
+
403
411
/** If this is an encoding of a (partially) applied type, return its arguments,
404
412
* otherwise return Nil.
405
413
* Existential types in arguments are returned as TypeBounds instances.
0 commit comments