aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-08-08 17:38:59 +0200
committerMartin Odersky <odersky@gmail.com>2013-08-08 17:38:59 +0200
commit7f8ce8379296a399d29fdf9ec91210f44460f98f (patch)
tree3957107d3c81e28a382ef898d34297d1be0b1131 /src/dotty/tools/dotc/typer/Typer.scala
parentdb9f555e2f02ac345945cb3982b0bf872f44a880 (diff)
downloaddotty-7f8ce8379296a399d29fdf9ec91210f44460f98f.tar.gz
dotty-7f8ce8379296a399d29fdf9ec91210f44460f98f.tar.bz2
dotty-7f8ce8379296a399d29fdf9ec91210f44460f98f.zip
Typing of return statements.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 32bb4f4d1..554884382 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -482,6 +482,25 @@ class Typer extends Namer with Applications with Implicits {
cpy.Match(tree, sel1, cases1).withType(ctx.lub(cases1.tpes))
}
+ def typedReturn(tree: untpd.Return)(implicit ctx: Context): Return = {
+ def enclMethInfo(cx: Context): (Tree, Type) =
+ if (cx == NoContext || cx.tree.isInstanceOf[Trees.TypeDef[_]]) {
+ ctx.error(s"return outside method definition")
+ (EmptyTree, WildcardType)
+ }
+ else cx.tree match {
+ case ddef: DefDef =>
+ val meth = ddef.symbol
+ (Ident(TermRef.withSym(NoPrefix, meth.asTerm)),
+ if (meth.isConstructor) defn.UnitType else ddef.tpt.tpe)
+ case _ =>
+ enclMethInfo(cx.outer)
+ }
+ val (from, proto) = enclMethInfo(ctx)
+ val expr1 = typedExpr(if (tree.expr.isEmpty) untpd.unitLiteral else tree.expr, proto)
+ cpy.Return(tree, expr1, from) withType defn.NothingType
+ }
+
def typedModifiers(mods: untpd.Modifiers)(implicit ctx: Context): Modifiers = {
val annotations1 = mods.annotations mapconserve typedAnnotation
if (annotations1 eq mods.annotations) mods.asInstanceOf[Modifiers]