File tree 5 files changed +22
-4
lines changed
compiler/src/dotty/tools/dotc
5 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -372,7 +372,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
372
372
ref(defn.DottyArraysModule ).select(defn.newArrayMethod).withPos(pos)
373
373
374
374
if (! ctx.erasedTypes) {
375
- assert(! TypeErasure .isUnboundedGeneric (elemTpe)) // needs to be done during typer. See Applications.convertNewGenericArray
375
+ assert(! TypeErasure .isGeneric (elemTpe)) // needs to be done during typer. See Applications.convertNewGenericArray
376
376
newArr.appliedToTypeTrees(TypeTree (returnTpe) :: Nil ).appliedToArgs(clsOf(elemTpe) :: clsOf(returnTpe) :: dims :: Nil ).withPos(pos)
377
377
} else // after erasure
378
378
newArr.appliedToArgs(clsOf(elemTpe) :: clsOf(returnTpe) :: dims :: Nil ).withPos(pos)
Original file line number Diff line number Diff line change @@ -216,6 +216,16 @@ object TypeErasure {
216
216
case _ => false
217
217
}
218
218
219
+ /** Is `tp` an abstract type or polymorphic type parameter, or another unbounded generic type? */
220
+ def isGeneric (tp : Type )(implicit ctx : Context ): Boolean = tp.dealias match {
221
+ case tp : TypeRef => ! tp.symbol.isClass
222
+ case tp : TypeParamRef => true
223
+ case tp : TypeProxy => isGeneric(tp.underlying)
224
+ case tp : AndType => isGeneric(tp.tp1) || isGeneric(tp.tp2)
225
+ case tp : OrType => isGeneric(tp.tp1) || isGeneric(tp.tp2)
226
+ case _ => false
227
+ }
228
+
219
229
/** The erased least upper bound is computed as follows
220
230
* - if both argument are arrays of objects, an array of the erased lub of the element types
221
231
* - if both arguments are arrays of same primitives, an array of this primitive
Original file line number Diff line number Diff line change @@ -46,10 +46,10 @@ class ArrayConstructors extends MiniPhase {
46
46
val cs = tp.tpe.widen.classSymbol
47
47
tree.fun match {
48
48
case Apply (TypeApply (t : Ident , targ), dims)
49
- if ! TypeErasure .isUnboundedGeneric (targ.head.tpe) && ! ValueClasses .isDerivedValueClass(cs) =>
49
+ if ! TypeErasure .isGeneric (targ.head.tpe) && ! ValueClasses .isDerivedValueClass(cs) =>
50
50
rewrite(targ.head.tpe, dims)
51
51
case Apply (TypeApply (t : Select , targ), dims)
52
- if ! TypeErasure .isUnboundedGeneric (targ.head.tpe) && ! ValueClasses .isDerivedValueClass(cs) =>
52
+ if ! TypeErasure .isGeneric (targ.head.tpe) && ! ValueClasses .isDerivedValueClass(cs) =>
53
53
Block (t.qualifier :: Nil , rewrite(targ.head.tpe, dims))
54
54
case _ => tree
55
55
}
Original file line number Diff line number Diff line change @@ -831,7 +831,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
831
831
.select(defn.newGenericArrayMethod).withPos(tree.pos)
832
832
.appliedToTypeTrees(targs).appliedToArgs(args)
833
833
834
- if (TypeErasure .isUnboundedGeneric (targ.tpe))
834
+ if (TypeErasure .isGeneric (targ.tpe))
835
835
newGenericArrayCall
836
836
else tree
837
837
case _ =>
Original file line number Diff line number Diff line change
1
+ import scala .reflect .ClassTag
2
+
3
+ object Test {
4
+ def foo [T <: AnyRef : ClassTag ] = new Array [T ](42 )
5
+ def main (args : Array [String ]): Unit = {
6
+ val x : Array [String ] = foo[String ]
7
+ }
8
+ }
You can’t perform that action at this time.
0 commit comments