From b1cded37763b0b96b9a8881c2d06f85b4d49884e Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 12 Feb 2015 20:48:16 +0100 Subject: Change scheme of translating array creations new Array(...) The previous scheme generated too many newGenericArray expressions because at the time newArray was called, the type arguments were not yet determined. Furthermore, the type variables somehow did not have the right positions, which caused them not to be interpolated and led to orphan PolyParams. The new scheme converts the expression when the length parameter has been supplied and it fully determines the array type before converting. --- src/dotty/tools/dotc/typer/Applications.scala | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/dotty/tools/dotc/typer/Applications.scala') diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index 47dfe157d..582642325 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -530,7 +530,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) val result = app.result - ConstFold(result) + convertNewArray(ConstFold(result)) } { (failedVal, failedState) => val fun2 = tryInsertImplicitOnQualifier(fun1, proto) if (fun1 eq fun2) { @@ -596,14 +596,14 @@ trait Applications extends Compatibility { self: Typer => checkBounds(typedArgs, pt) case _ => } - convertNewArray( - assignType(cpy.TypeApply(tree)(typedFn, typedArgs), typedFn, typedArgs)) + assignType(cpy.TypeApply(tree)(typedFn, typedArgs), typedFn, typedArgs) } - /** Rewrite `new Array[T]` trees to calls of newXYZArray methods. */ - def convertNewArray(tree: Tree)(implicit ctx: Context): Tree = tree match { - case TypeApply(tycon, targs) if tycon.symbol == defn.ArrayConstructor => - newArray(targs.head, tree.pos) + /** Rewrite `new Array[T](....)` trees to calls of newXYZArray methods. */ + 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) + tpd.cpy.Apply(tree)(newArray(targ, tree.pos), args) case _ => tree } -- cgit v1.2.3