Skip to content

Commit a756db9

Browse files
committed
ArrayConstructors: don't optimise creating of multi-dim generic arrays.
They need to be created through their class tag.
1 parent 55174aa commit a756db9

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/dotty/tools/dotc/transform/ArrayConstructors.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ import collection.mutable
2121
import ResolveSuper._
2222

2323

24-
/** This phase rewrites calls to array constructors to newArray and newGenericArray methods
25-
* in Dotty.runtime.Arrays module.
26-
*
27-
* Additionally it optimizes calls to scala.Array.ofDim functions
28-
*
29-
*/
24+
/** This phase rewrites calls to array constructors to newArray method in Dotty.runtime.Arrays module.
25+
*
26+
* It assummes that generic arrays have already been handled by typer(see Applications.convertNewGenericArray).
27+
* Additionally it optimizes calls to scala.Array.ofDim functions by replacing them with calls to newArray with specific dimensions
28+
*/
3029
class ArrayConstructors extends MiniPhaseTransform { thisTransform =>
3130
import ast.tpd._
3231

@@ -46,9 +45,9 @@ class ArrayConstructors extends MiniPhaseTransform { thisTransform =>
4645
} else if ((tree.fun.symbol.maybeOwner eq defn.ArrayModule) && (tree.fun.symbol.name eq nme.ofDim) && !tree.tpe.isInstanceOf[MethodicType]) {
4746

4847
tree.fun match {
49-
case Apply(TypeApply(t: Ident, targ), dims) =>
48+
case Apply(TypeApply(t: Ident, targ), dims) if !TypeErasure.isUnboundedGeneric(targ.head.tpe) =>
5049
rewrite(targ.head.tpe, dims)
51-
case Apply(TypeApply(t: Select, targ), dims) =>
50+
case Apply(TypeApply(t: Select, targ), dims) if !TypeErasure.isUnboundedGeneric(targ.head.tpe) =>
5251
Block(t.qualifier :: Nil, rewrite(targ.head.tpe, dims))
5352
case _ => tree
5453
}

0 commit comments

Comments
 (0)