Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ object TypeErasure {
}
}

/** Is `tp` an abstract type or polymorphic type parameter that has `Any`
* as upper bound and that is not Java defined? Arrays of such types are
* erased to `Object` instead of `ObjectArray`.
/** Is `tp` an abstract type or polymorphic type parameter that has `Any`, `AnyVal`,
* or a universal trait as upper bound and that is not Java defined? Arrays of such types are
* erased to `Object` instead of `Object[]`.
*/
def isUnboundedGeneric(tp: Type)(implicit ctx: Context): Boolean = tp.dealias match {
case tp: TypeRef =>
Expand All @@ -182,13 +182,14 @@ object TypeErasure {
case tp: PolyParam =>
!tp.derivesFrom(defn.ObjectClass) &&
!tp.binder.resultType.isInstanceOf[JavaMethodType]
case tp: TypeAlias => isUnboundedGeneric(tp.alias)
case tp: TypeBounds => !tp.hi.derivesFrom(defn.ObjectClass)
case tp: TypeProxy => isUnboundedGeneric(tp.underlying)
case tp: AndType => isUnboundedGeneric(tp.tp1) || isUnboundedGeneric(tp.tp2)
case tp: OrType => isUnboundedGeneric(tp.tp1) && isUnboundedGeneric(tp.tp2)
case _ => false
}


/** The erased least upper bound is computed as follows
* - if both argument are arrays, an array of the lub of the element types
* - if one argument is an array, Object
Expand Down
6 changes: 6 additions & 0 deletions tests/pos/i540.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
trait Foo extends Any

object Univ {
def univ[T <: Foo](x: Array[T]) = {}
def univ2(x: Array[_ <: Foo]) = {}
}