aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-10-26 10:29:45 +0200
committerMartin Odersky <odersky@gmail.com>2013-10-26 10:29:50 +0200
commit961c0569eb0a54cf95363bab79add43da310984c (patch)
treeefe723b1b6a182ec0f99c5f3d33b78a5a90d8bdf /src/dotty/tools/dotc/typer
parent8c1cc60c7ef9c13b312fceaf6cb8c8c129753344 (diff)
downloaddotty-961c0569eb0a54cf95363bab79add43da310984c.tar.gz
dotty-961c0569eb0a54cf95363bab79add43da310984c.tar.bz2
dotty-961c0569eb0a54cf95363bab79add43da310984c.zip
Fixed handling of varargs
Diffstat (limited to 'src/dotty/tools/dotc/typer')
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala16
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala12
2 files changed, 13 insertions, 15 deletions
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index 0abaa17fe..e2e40e7e2 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -327,17 +327,10 @@ trait Applications extends Compatibility { self: Typer =>
init()
}
- /** Subtrait of Application for the cases where arguments are (typed or
- * untyped) trees.
- */
- trait TreeApplication[T >: Untyped] extends Application[Trees.Tree[T]] {
- type TypeArg = Tree
- def isVarArg(arg: Trees.Tree[T]): Boolean = isWildcardStarArg(arg)
- }
-
/** Subclass of Application for applicability tests with trees as arguments. */
class ApplicableToTrees(methRef: TermRef, args: List[Tree], resultType: Type)(implicit ctx: Context)
- extends TestApplication(methRef, methRef, args, resultType) with TreeApplication[Type] {
+ extends TestApplication(methRef, methRef, args, resultType) {
+ def isVarArg(arg: Tree): Boolean = tpd.isWildcardStarArg(arg)
def argType(arg: Tree): Type = normalize(arg.tpe)
def treeToArg(arg: Tree): Tree = arg
}
@@ -355,8 +348,9 @@ trait Applications extends Compatibility { self: Typer =>
*/
abstract class TypedApply[T >: Untyped](
app: untpd.Apply, fun: Tree, methRef: TermRef, args: List[Trees.Tree[T]], resultType: Type)(implicit ctx: Context)
- extends Application(methRef, fun.tpe, args, resultType) with TreeApplication[T] {
+ extends Application(methRef, fun.tpe, args, resultType) {
type TypedArg = Tree
+ def isVarArg(arg: Trees.Tree[T]): Boolean = untpd.isWildcardStarArg(arg)
private var typedArgBuf = new mutable.ListBuffer[Tree]
private var liftedDefs: mutable.ListBuffer[Tree] = null
private var myNormalizedFun: Tree = fun
@@ -369,7 +363,7 @@ trait Applications extends Compatibility { self: Typer =>
val args = typedArgBuf.takeRight(n).toList
typedArgBuf.trimEnd(n)
val seqLit = if (methodType.isJava) JavaSeqLiteral(args) else SeqLiteral(args)
- typedArgBuf += seqLit
+ typedArgBuf += seqToRepeated(seqLit)
}
def fail(msg: => String, arg: Trees.Tree[T]) = {
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index a22d128e3..1bdc5516c 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -407,9 +407,13 @@ class Typer extends Namer with Applications with Implicits {
import untpd._
typed(Bind(id.name, Typed(Ident(nme.WILDCARD), tree.tpt)).withPos(id.pos))
case _ =>
- val tpt1 = typedType(tree.tpt)
- val expr1 = typedExpr(tree.expr, tpt1.tpe)
- cpy.Typed(tree, expr1, tpt1).withType(tpt1.tpe)
+ if (untpd.isWildcardStarArg(tree))
+ seqToRepeated(typedExpr(tree.expr, defn.SeqType))
+ else {
+ val tpt1 = typedType(tree.tpt)
+ val expr1 = typedExpr(tree.expr, tpt1.tpe)
+ cpy.Typed(tree, expr1, tpt1).withType(tpt1.tpe)
+ }
}
}
@@ -608,7 +612,7 @@ class Typer extends Namer with Applications with Implicits {
def typedSeqLiteral(tree: untpd.SeqLiteral, pt: Type)(implicit ctx: Context): SeqLiteral = track("typedSeqLiteral") {
val proto1 = pt.elemType orElse WildcardType
val elems1 = tree.elems mapconserve (typed(_, proto1))
- cpy.SeqLiteral(tree, elems1) withType ctx.typeComparer.lub(elems1.tpes)
+ cpy.SeqLiteral(tree, elems1) withType defn.SeqType.appliedTo(ctx.typeComparer.lub(elems1.tpes))
}
def typedTypeTree(tree: untpd.TypeTree, pt: Type)(implicit ctx: Context): TypeTree = track("typedTypeTree") {