Skip to content

Commit 3005b92

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 b194ed1 commit 3005b92

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
@@ -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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
16711671
case _ => Nil
16721672
}
16731673
if (typeArgs.isEmpty) typeArgs = constrained(poly, tree)._2
1674-
adaptInterpolated(tree.appliedToTypes(typeArgs), pt, original)
1674+
convertNewArray(
1675+
adaptInterpolated(tree.appliedToTypes(typeArgs), pt, original))
16751676
}
16761677
case wtp =>
16771678
pt match {

0 commit comments

Comments
 (0)