aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Applications.scala
diff options
context:
space:
mode:
authorDmitry Petrashko <dmitry.petrashko@gmail.com>2016-03-30 17:27:41 +0200
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2016-04-18 14:46:57 +0200
commitc74bb42251eb233c858810d83300ba78876a2b2c (patch)
tree61dd238b9103b9813e907faa69b77c8f47654b6e /src/dotty/tools/dotc/typer/Applications.scala
parent9d7db0c2fff12420f7ef37119746860622e40387 (diff)
downloaddotty-c74bb42251eb233c858810d83300ba78876a2b2c.tar.gz
dotty-c74bb42251eb233c858810d83300ba78876a2b2c.tar.bz2
dotty-c74bb42251eb233c858810d83300ba78876a2b2c.zip
Separate handling of genericArray creation from normal ones.
This allowed to simplify the code in both Applications and tpd.newArray. Now, only creation of generic arrays is handled by typer. All other arrays are handled in ArrayConstructors phase.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Applications.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index 7fb71b7fb..2cec4bf08 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
- convertNewArray(ConstFold(result))
+ convertNewGenericArray(ConstFold(result))
} { (failedVal, failedState) =>
val fun2 = tryInsertImplicitOnQualifier(fun1, proto)
if (fun1 eq fun2) {
@@ -636,14 +636,20 @@ 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.
+ /** Rewrite `new Array[T](....)` if T is an unbounded generic to calls to newGenericArray.
* It is performed during typer as creation of generic arrays needs a classTag.
- * we rely on implicit search to find one
+ * 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 =>
+ def convertNewGenericArray(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match {
+ case Apply(TypeApply(tycon, targs@(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)))
+
+ def newGenericArrayCall =
+ ref(defn.DottyArraysModule).select(defn.newGenericArrayMethod).withPos(tree.pos).appliedToTypeTrees(targs).appliedToArgs(args)
+
+ if (TypeErasure.isUnboundedGeneric(targ.tpe))
+ newGenericArrayCall
+ else tree
case _ =>
tree
}