Skip to content

Commit 14e5ae5

Browse files
committed
Merge pull request #542 from dotty-staging/fix/#540-unbounded-generic-array
Fix #540 - unbounded array test for wildcard array arguments
2 parents 905c541 + df0e140 commit 14e5ae5

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ object TypeErasure {
170170
}
171171
}
172172

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

191-
192193
/** The erased least upper bound is computed as follows
193194
* - if both argument are arrays, an array of the lub of the element types
194195
* - if one argument is an array, Object

tests/pos/i540.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
trait Foo extends Any
2+
3+
object Univ {
4+
def univ[T <: Foo](x: Array[T]) = {}
5+
def univ2(x: Array[_ <: Foo]) = {}
6+
}

0 commit comments

Comments
 (0)