aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-08-10 12:32:04 +0200
committerMartin Odersky <odersky@gmail.com>2013-08-10 12:32:04 +0200
commit4b32ec471bafe988b64563aaabf2d273220a8644 (patch)
treef9a1530385e8fc9e0d1ded6b1c755f140fd3b64e /src/dotty/tools/dotc
parentd318cafbb92518a39c84539c0387c2c93815bb7a (diff)
downloaddotty-4b32ec471bafe988b64563aaabf2d273220a8644.tar.gz
dotty-4b32ec471bafe988b64563aaabf2d273220a8644.tar.bz2
dotty-4b32ec471bafe988b64563aaabf2d273220a8644.zip
Added typing of Alternatives.
Also changed some maps to mapconserves to avoid unnecessary tree copying.
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala13
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala19
2 files changed, 19 insertions, 13 deletions
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index 242acc43b..334e21ccb 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -467,7 +467,7 @@ trait Applications extends Compatibility { self: Typer =>
}
if (sameSeq(typedArgs, args)) // trick to cut down on tree copying
typedArgs = args.asInstanceOf[List[Tree]]
- methodType.instantiate(typedArgs map (_.tpe))
+ methodType.instantiate(typedArgs.tpes)
}
val app1 = cpy.Apply(app, normalizedFun, typedArgs).withType(ownType)
if (liftedDefs != null && liftedDefs.nonEmpty) Block(liftedDefs.toList, app1)
@@ -497,7 +497,7 @@ trait Applications extends Compatibility { self: Typer =>
def typedApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree = {
if (ctx.mode is Mode.Pattern)
- typedUnApply(tree.fun, tree.args, tree, pt)
+ typedUnApply(tree, pt)
else {
def realApply(implicit ctx: Context) = {
@@ -544,11 +544,11 @@ trait Applications extends Compatibility { self: Typer =>
def typedTypeApply(tree: untpd.TypeApply, pt: Type)(implicit ctx: Context): Tree = {
val typedFn = typedExpr(tree.fun, PolyProtoType(tree.args.length, pt))
- val typedArgs = tree.args map (typedType(_))
+ val typedArgs = tree.args mapconserve (typedType(_))
val ownType = typedFn.tpe.widen match {
case pt: PolyType =>
checkBounds(typedArgs, pt, tree.pos)
- pt.resultType.substParams(pt, typedArgs map (_.tpe))
+ pt.resultType.substParams(pt, typedArgs.tpes)
case _ =>
ctx.error(s"${err.exprStr(typedFn)} does not take type parameters", tree.pos)
ErrorType
@@ -556,7 +556,8 @@ trait Applications extends Compatibility { self: Typer =>
cpy.TypeApply(tree, typedFn, typedArgs).withType(ownType)
}
- def typedUnApply(qual: untpd.Tree, args: List[untpd.Tree], tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree = {
+ def typedUnApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree = {
+ val Apply(qual, args) = tree
def unapplyArgs(unapplyResult: Type)(implicit ctx: Context): List[Type] = {
def recur(tp: Type): List[Type] = {
@@ -646,7 +647,7 @@ trait Applications extends Compatibility { self: Typer =>
else Typed(result, TypeTree(ownType))
case tp =>
val unapplyErr = if (tp.isError) unapply else notAnExtractor(unapply)
- val typedArgsErr = args map (typed(_, defn.AnyType))
+ val typedArgsErr = args mapconserve (typed(_, defn.AnyType))
cpy.UnApply(tree, unapplyErr, typedArgsErr) withType ErrorType
}
}
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 0869aff43..e81672eda 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -438,7 +438,7 @@ class Typer extends Namer with Applications with Implicits {
}
def typedClosure(tree: untpd.Closure, pt: Type)(implicit ctx: Context) = {
- val env1 = tree.env map (typed(_))
+ val env1 = tree.env mapconserve (typed(_))
val meth1 = typed(tree.meth)
val ownType = meth1.tpe.widen match {
case mt: MethodType if !mt.isDependent =>
@@ -492,7 +492,7 @@ class Typer extends Namer with Applications with Implicits {
(doCase /: gadtSyms) ((op, tsym) => tsym.withGADTFlexType(op)) ()
}
- val cases1 = tree.cases map typedCase
+ val cases1 = tree.cases mapconserve typedCase
cpy.Match(tree, sel1, cases1).withType(ctx.lub(cases1.tpes))
}
@@ -540,7 +540,7 @@ class Typer extends Namer with Applications with Implicits {
def typedSeqLiteral(tree: untpd.SeqLiteral, pt: Type)(implicit ctx: Context): SeqLiteral = {
val proto1 = pt.elemType orElse WildcardType
- val elems1 = tree.elems map (typed(_, proto1))
+ val elems1 = tree.elems mapconserve (typed(_, proto1))
cpy.SeqLiteral(tree, elems1) withType ctx.lub(elems1.tpes)
}
@@ -606,7 +606,7 @@ class Typer extends Namer with Applications with Implicits {
def typedAppliedTypeTree(tree: untpd.AppliedTypeTree)(implicit ctx: Context): AppliedTypeTree = {
val tpt1 = typed(tree.tpt)
- val args1 = tree.args map (typed(_))
+ val args1 = tree.args mapconserve (typed(_))
val tparams = tpt1.tpe.typeParams
if (args1.length != tparams.length)
ctx.error(s"wrong number of type arguments for ${tpt1.tpe.show}, should be ${tparams.length}")
@@ -628,6 +628,11 @@ class Typer extends Namer with Applications with Implicits {
cpy.Bind(tree, tree.name, body1) withType TermRef.withSym(NoPrefix, sym)
}
+ def typedAlternative(tree: untpd.Alternative, pt: Type)(implicit ctx: Context): Alternative = {
+ val trees1 = tree.trees mapconserve (typed(_, pt))
+ cpy.Alternative(tree, trees1) withType ctx.lub(trees1.tpes)
+ }
+
def typedModifiers(mods: untpd.Modifiers)(implicit ctx: Context): Modifiers = {
val annotations1 = mods.annotations mapconserve typedAnnotation
if (annotations1 eq mods.annotations) mods.asInstanceOf[Modifiers]
@@ -642,15 +647,15 @@ class Typer extends Namer with Applications with Implicits {
val mods1 = typedModifiers(mods)
val tpt1 = typedType(tpt)
val rhs1 = typedExpr(rhs, tpt1.tpe)
- val pt = if (sym.exists) sym.symRef else NoType
- cpy.ValDef(vdef, mods1, name, tpt1, rhs1).withType(pt)
+ val refType = if (sym.exists) sym.symRef else NoType
+ cpy.ValDef(vdef, mods1, name, tpt1, rhs1).withType(refType)
}
def typedDefDef(ddef: untpd.DefDef, sym: Symbol)(implicit ctx: Context) = {
val DefDef(mods, name, tparams, vparamss, tpt, rhs) = ddef
val mods1 = typedModifiers(mods)
val tparams1 = tparams mapconserve (typed(_).asInstanceOf[TypeDef])
- val vparamss1 = vparamss.mapconserve(_ mapconserve (typed(_).asInstanceOf[ValDef]))
+ val vparamss1 = vparamss mapconserve(_ mapconserve (typed(_).asInstanceOf[ValDef]))
val tpt1 = typedType(tpt)
val rhs1 = typedExpr(rhs, tpt1.tpe)
cpy.DefDef(ddef, mods1, name, tparams1, vparamss1, tpt1, rhs1).withType(sym.symRef)