diff options
Diffstat (limited to 'src/dotty/tools/dotc/typer')
-rw-r--r-- | src/dotty/tools/dotc/typer/Applications.scala | 14 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 3 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index c0664e0d6..7fb71b7fb 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -560,7 +560,7 @@ trait Applications extends Compatibility { self: Typer => if (proto.argsAreTyped) new ApplyToTyped(tree, fun1, funRef, proto.typedArgs, pt) else new ApplyToUntyped(tree, fun1, funRef, proto, pt)(argCtx(tree)) val result = app.result - ConstFold(result) + convertNewArray(ConstFold(result)) } { (failedVal, failedState) => val fun2 = tryInsertImplicitOnQualifier(fun1, proto) if (fun1 eq fun2) { @@ -636,6 +636,18 @@ trait Applications extends Compatibility { self: Typer => def adaptTypeArg(tree: tpd.Tree, bound: Type)(implicit ctx: Context): tpd.Tree = tree.withType(tree.tpe.etaExpandIfHK(bound)) + /** Rewrite `new Array[T](....)` trees to calls of newXYZArray methods. + * It is performed during typer as creation of generic arrays needs a classTag. + * we rely on implicit search to find one + */ + def convertNewArray(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match { + case Apply(TypeApply(tycon, targ :: Nil), args) if tycon.symbol == defn.ArrayConstructor => + fullyDefinedType(tree.tpe, "array", tree.pos) + newArray(targ.tpe, tree.tpe, tree.pos, JavaSeqLiteral(args, TypeTree(defn.IntClass.typeRef))) + case _ => + tree + } + def typedUnApply(tree: untpd.Apply, selType: Type)(implicit ctx: Context): Tree = track("typedUnApply") { val Apply(qual, args) = tree diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 6a8e93f86..2575dbec2 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1684,7 +1684,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit case _ => Nil } if (typeArgs.isEmpty) typeArgs = constrained(poly, tree)._2 - adaptInterpolated(tree.appliedToTypes(typeArgs), pt, original) + convertNewArray( + adaptInterpolated(tree.appliedToTypes(typeArgs), pt, original)) } case wtp => pt match { |