diff options
author | Martin Odersky <odersky@gmail.com> | 2016-02-19 15:47:44 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-02-20 10:19:58 +0100 |
commit | 14096e3601e42fd33fb2446b908a5cfce3cf1fa9 (patch) | |
tree | fb31ac66bb478d901adbff66d257e4c00aeec585 /src/dotty/tools/dotc/typer/Typer.scala | |
parent | c6064ed02c4d895b1d0df269fc018265b0d55625 (diff) | |
download | dotty-14096e3601e42fd33fb2446b908a5cfce3cf1fa9.tar.gz dotty-14096e3601e42fd33fb2446b908a5cfce3cf1fa9.tar.bz2 dotty-14096e3601e42fd33fb2446b908a5cfce3cf1fa9.zip |
Refactoring of typedTyped
Goal: Make implementation easier to understand. Prepare the ground for
special-casing of typetagged patterns.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 1e8e3a524..fabee83b7 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -400,30 +400,38 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } def typedTyped(tree: untpd.Typed, pt: Type)(implicit ctx: Context): Tree = track("typedTyped") { - def regularTyped(isWildcard: Boolean) = { - val tpt1 = - if (untpd.isWildcardStarArg(tree)) - TypeTree(defn.SeqType.appliedTo(pt :: Nil)) - else - checkSimpleKinded(typedType(tree.tpt)) - val expr1 = - if (isWildcard) tree.expr withType tpt1.tpe - else typed(tree.expr, tpt1.tpe.widenSkolem) - assignType(cpy.Typed(tree)(expr1, tpt1), tpt1) - } - tree.expr match { + /* Handles three cases: + * @param ifPat how to handle a pattern (_: T) + * @param ifExpr how to handle an expression (e: T) + * @param wildName what name `w` to use in the rewriting of + * (x: T) to (x @ (w: T)). This is either `_` or `_*`. + */ + def cases(ifPat: => Tree, ifExpr: => Tree, wildName: TermName) = tree.expr match { case id: untpd.Ident if (ctx.mode is Mode.Pattern) && isVarPattern(id) => - if (id.name == nme.WILDCARD || id.name == nme.WILDCARD_STAR) regularTyped(isWildcard = true) + if (id.name == nme.WILDCARD || id.name == nme.WILDCARD_STAR) ifPat else { import untpd._ - val name = if (untpd.isWildcardStarArg(tree)) nme.WILDCARD_STAR else nme.WILDCARD - typed(Bind(id.name, Typed(Ident(name), tree.tpt)).withPos(id.pos), pt) + typed(Bind(id.name, Typed(Ident(wildName), tree.tpt)).withPos(id.pos), pt) } - case _ => - if (untpd.isWildcardStarArg(tree)) - seqToRepeated(typedExpr(tree.expr, defn.SeqType)) - else - regularTyped(isWildcard = false) + case _ => ifExpr + } + def ascription(tpt: Tree, isWildcard: Boolean) = { + val expr1 = + if (isWildcard) tree.expr.withType(tpt.tpe) + else typed(tree.expr, tpt.tpe.widenSkolem) + assignType(cpy.Typed(tree)(expr1, tpt), tpt) + } + if (untpd.isWildcardStarArg(tree)) + cases( + ifPat = ascription(TypeTree(defn.SeqType.appliedTo(pt :: Nil)), isWildcard = true), + ifExpr = seqToRepeated(typedExpr(tree.expr, defn.SeqType)), + wildName = nme.WILDCARD_STAR) + else { + def tpt1 = checkSimpleKinded(typedType(tree.tpt)) + cases( + ifPat = ascription(tpt1, isWildcard = true), + ifExpr = ascription(tpt1, isWildcard = false), + wildName = nme.WILDCARD) } } |