@@ -435,15 +435,19 @@ class TypeApplications(val self: Type) extends AnyVal {
435
435
case _ => if (self.isMatch) MatchAlias (self) else TypeAlias (self)
436
436
}
437
437
438
- /** Translate a type of the form From[T] to To[T], keep other types as they are.
438
+ /** Translate a type of the form From[T] to either To[T] or To[_ <: T] (if `wildcardArg` is set). Keep other types as they are.
439
439
* `from` and `to` must be static classes, both with one type parameter, and the same variance.
440
440
* Do the same for by name types => From[T] and => To[T]
441
441
*/
442
- def translateParameterized (from : ClassSymbol , to : ClassSymbol )(implicit ctx : Context ): Type = self match {
442
+ def translateParameterized (from : ClassSymbol , to : ClassSymbol , wildcardArg : Boolean = false )(implicit ctx : Context ): Type = self match {
443
443
case self @ ExprType (tp) =>
444
444
self.derivedExprType(tp.translateParameterized(from, to))
445
445
case _ =>
446
- if (self.derivesFrom(from)) to.typeRef.appliedTo(self.baseType(from).argInfos)
446
+ if (self.derivesFrom(from)) {
447
+ val arg = self.baseType(from).argInfos.head
448
+ val arg1 = if (wildcardArg) TypeBounds .upper(arg) else arg
449
+ to.typeRef.appliedTo(arg1)
450
+ }
447
451
else self
448
452
}
449
453
@@ -453,7 +457,9 @@ class TypeApplications(val self: Type) extends AnyVal {
453
457
def underlyingIfRepeated (isJava : Boolean )(implicit ctx : Context ): Type =
454
458
if (self.isRepeatedParam) {
455
459
val seqClass = if (isJava) defn.ArrayClass else defn.SeqClass
456
- translateParameterized(defn.RepeatedParamClass , seqClass)
460
+ // If `isJava` is set, then we want to turn `RepeatedParam[T]` into `Array[_ <: T]`,
461
+ // since arrays aren't covariant until after erasure. See `tests/pos/i5140`.
462
+ translateParameterized(defn.RepeatedParamClass , seqClass, wildcardArg = isJava)
457
463
}
458
464
else self
459
465
0 commit comments