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