Skip to content

Commit 9d7db0c

Browse files
committed
Bring back convertNewArray into typer.
It's needed in order to create calls to newGenricArray as it needs to infer the ClassTag.
1 parent 2c370bd commit 9d7db0c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
16841684
case _ => Nil
16851685
}
16861686
if (typeArgs.isEmpty) typeArgs = constrained(poly, tree)._2
1687-
adaptInterpolated(tree.appliedToTypes(typeArgs), pt, original)
1687+
convertNewArray(
1688+
adaptInterpolated(tree.appliedToTypes(typeArgs), pt, original))
16881689
}
16891690
case wtp =>
16901691
pt match {

0 commit comments

Comments
 (0)