File tree 2 files changed +11
-4
lines changed
src/dotty/tools/dotc/core
2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -170,9 +170,9 @@ object TypeErasure {
170
170
}
171
171
}
172
172
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[] `.
176
176
*/
177
177
def isUnboundedGeneric (tp : Type )(implicit ctx : Context ): Boolean = tp.dealias match {
178
178
case tp : TypeRef =>
@@ -182,13 +182,14 @@ object TypeErasure {
182
182
case tp : PolyParam =>
183
183
! tp.derivesFrom(defn.ObjectClass ) &&
184
184
! tp.binder.resultType.isInstanceOf [JavaMethodType ]
185
+ case tp : TypeAlias => isUnboundedGeneric(tp.alias)
186
+ case tp : TypeBounds => ! tp.hi.derivesFrom(defn.ObjectClass )
185
187
case tp : TypeProxy => isUnboundedGeneric(tp.underlying)
186
188
case tp : AndType => isUnboundedGeneric(tp.tp1) || isUnboundedGeneric(tp.tp2)
187
189
case tp : OrType => isUnboundedGeneric(tp.tp1) && isUnboundedGeneric(tp.tp2)
188
190
case _ => false
189
191
}
190
192
191
-
192
193
/** The erased least upper bound is computed as follows
193
194
* - if both argument are arrays, an array of the lub of the element types
194
195
* - if one argument is an array, Object
Original file line number Diff line number Diff line change
1
+ trait Foo extends Any
2
+
3
+ object Univ {
4
+ def univ [T <: Foo ](x : Array [T ]) = {}
5
+ def univ2 (x : Array [_ <: Foo ]) = {}
6
+ }
You can’t perform that action at this time.
0 commit comments