@@ -556,7 +556,7 @@ trait Applications extends Compatibility { self: Typer =>
556556 if (proto.argsAreTyped) new ApplyToTyped (tree, fun1, funRef, proto.typedArgs, pt)
557557 else new ApplyToUntyped (tree, fun1, funRef, proto, pt)(argCtx)
558558 val result = app.result
559- ConstFold (result)
559+ convertNewArray( ConstFold (result) )
560560 } { (failedVal, failedState) =>
561561 val fun2 = tryInsertImplicitOnQualifier(fun1, proto)
562562 if (fun1 eq fun2) {
@@ -632,6 +632,18 @@ trait Applications extends Compatibility { self: Typer =>
632632 def adaptTypeArg (tree : tpd.Tree , bound : Type )(implicit ctx : Context ): tpd.Tree =
633633 tree.withType(tree.tpe.etaExpandIfHK(bound))
634634
635+ /** Rewrite `new Array[T](....)` trees to calls of newXYZArray methods.
636+ * It is performed during typer as creation of generic arrays needs a classTag.
637+ * we rely on implicit search to find one
638+ */
639+ def convertNewArray (tree : tpd.Tree )(implicit ctx : Context ): tpd.Tree = tree match {
640+ case Apply (TypeApply (tycon, targ :: Nil ), args) if tycon.symbol == defn.ArrayConstructor =>
641+ fullyDefinedType(tree.tpe, " array" , tree.pos)
642+ newArray(targ.tpe, tree.tpe, tree.pos, JavaSeqLiteral (args, TypeTree (defn.IntClass .typeRef)))
643+ case _ =>
644+ tree
645+ }
646+
635647 def typedUnApply (tree : untpd.Apply , selType : Type )(implicit ctx : Context ): Tree = track(" typedUnApply" ) {
636648 val Apply (qual, args) = tree
637649
0 commit comments