diff options
author | Martin Odersky <odersky@gmail.com> | 2006-04-12 16:32:54 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2006-04-12 16:32:54 +0000 |
commit | e205301999b5de273f985941d8eac9cfab283343 (patch) | |
tree | 64dd8f9aa37e21abe71ceb6c74e3d9d38d733b4e /src/compiler/scala/tools/nsc/typechecker/Typers.scala | |
parent | 99a85272928ab170351fa1f36b5684ae6a6b4755 (diff) | |
download | scala-e205301999b5de273f985941d8eac9cfab283343.tar.gz scala-e205301999b5de273f985941d8eac9cfab283343.tar.bz2 scala-e205301999b5de273f985941d8eac9cfab283343.zip |
Fixed bug 566
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 3e93ca194c..8b151063db 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -786,6 +786,7 @@ trait Typers requires Analyzer { checkNoEscaping.privates(meth, typedType(ddef.tpt))) checkNonCyclic(ddef, tpt1) + ddef.tpt.setType(tpt1.tpe) val rhs1 = if (ddef.name == nme.CONSTRUCTOR) { if (!meth.hasFlag(SYNTHETIC) && @@ -1405,14 +1406,16 @@ trait Typers requires Analyzer { copy.Match(tree, selector1, cases1) setType ptOrLub(cases1 map (.tpe)) case Return(expr) => - val enclFun = if (tree.symbol != NoSymbol) tree.symbol else context.owner.enclMethod - if (!enclFun.isMethod || enclFun.isConstructor) + val enclMethod = context.enclMethod; + if (enclMethod == NoContext || enclMethod.owner.isConstructor) errorTree(tree, "return outside method definition") - else if (!context.owner.isInitialized) - errorTree(tree, "method "+context.owner+" has return statement; needs result type") + else if (!enclMethod.owner.isInitialized) + errorTree(tree, "method "+enclMethod.owner+" has return statement; needs result type") else { - val expr1: Tree = typed(expr, enclFun.tpe.finalResultType) - copy.Return(tree, expr1) setSymbol enclFun setType AllClass.tpe + val DefDef(_, _, _, _, restpt, _) = enclMethod.tree + assert(restpt.tpe != null, restpt) + val expr1: Tree = typed(expr, restpt.tpe) + copy.Return(tree, expr1) setSymbol enclMethod.owner setType AllClass.tpe } case Try(block, catches, finalizer) => |