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 @@ -1427,14 +1427,11 @@ trait Applications extends Compatibility {
1427
1427
def convertNewGenericArray (tree : Tree )(using Context ): Tree = tree match {
1428
1428
case Apply (TypeApply (tycon, targs@ (targ :: Nil )), args) if tycon.symbol == defn.ArrayConstructor =>
1429
1429
fullyDefinedType(tree.tpe, " array" , tree.srcPos)
1430
-
1431
- def newGenericArrayCall =
1430
+ if TypeErasure .isGenericArrayArg(targ.tpe) then
1432
1431
ref(defn.DottyArraysModule )
1433
- .select(defn.newGenericArrayMethod).withSpan(tree.span)
1434
- .appliedToTypeTrees(targs).appliedToTermArgs(args)
1435
-
1436
- if (TypeErasure .isGeneric(targ.tpe))
1437
- newGenericArrayCall
1432
+ .select(defn.newGenericArrayMethod).withSpan(tree.span)
1433
+ .appliedToTypeTrees(targs)
1434
+ .appliedToTermArgs(args)
1438
1435
else tree
1439
1436
case _ =>
1440
1437
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