File tree Expand file tree Collapse file tree 3 files changed +18
-7
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -386,6 +386,12 @@ object TypeErasure {
386
386
case _ => false
387
387
}
388
388
389
+ /** Is `tp` of the form `Array^N[T]` where T is generic? */
390
+ def isGenericArrayArg (tp : Type )(using Context ): Boolean = tp.dealias match
391
+ case defn.ArrayOf (elem) => isGenericArrayArg(elem)
392
+ case _ => isGeneric(tp)
393
+ end isGenericArrayArg
394
+
389
395
/** The erased least upper bound of two erased types is computed as follows
390
396
* - if both argument are arrays of objects, an array of the erased lub of the element types
391
397
* - if both arguments are arrays of same primitives, an array of this primitive
Original file line number Diff line number Diff line change @@ -1282,14 +1282,11 @@ trait Applications extends Compatibility {
1282
1282
def convertNewGenericArray (tree : Tree )(using Context ): Tree = tree match {
1283
1283
case Apply (TypeApply (tycon, targs@ (targ :: Nil )), args) if tycon.symbol == defn.ArrayConstructor =>
1284
1284
fullyDefinedType(tree.tpe, " array" , tree.srcPos)
1285
-
1286
- def newGenericArrayCall =
1285
+ if TypeErasure .isGenericArrayArg(targ.tpe) then
1287
1286
ref(defn.DottyArraysModule )
1288
- .select(defn.newGenericArrayMethod).withSpan(tree.span)
1289
- .appliedToTypeTrees(targs).appliedToTermArgs(args)
1290
-
1291
- if (TypeErasure .isGeneric(targ.tpe))
1292
- newGenericArrayCall
1287
+ .select(defn.newGenericArrayMethod).withSpan(tree.span)
1288
+ .appliedToTypeTrees(targs)
1289
+ .appliedToTermArgs(args)
1293
1290
else tree
1294
1291
case _ =>
1295
1292
tree
Original file line number Diff line number Diff line change
1
+ import scala .reflect .ClassTag
2
+
3
+ object MyArray :
4
+ def empty [T : ClassTag ]: Array [Array [T ]] = new Array [Array [T ]](0 )
5
+
6
+ @ main def Test =
7
+ val arr : Array [Array [String ]] = MyArray .empty[String ]
8
+ assert(arr.length == 0 )
You can’t perform that action at this time.
0 commit comments