diff options
author | Tiark Rompf <tiark.rompf@epfl.ch> | 2010-02-10 14:21:57 +0000 |
---|---|---|
committer | Tiark Rompf <tiark.rompf@epfl.ch> | 2010-02-10 14:21:57 +0000 |
commit | 96a7efb1fd7db67c21ff5000d343765c925a83d7 (patch) | |
tree | 60e2bf2c548c6cda3f485edecd06fbe2f9804264 /src | |
parent | 1c8210ec7e42139c62271edc513597befa288167 (diff) | |
download | scala-96a7efb1fd7db67c21ff5000d343765c925a83d7.tar.gz scala-96a7efb1fd7db67c21ff5000d343765c925a83d7.tar.bz2 scala-96a7efb1fd7db67c21ff5000d343765c925a83d7.zip |
modified typing of while loops to allow other t...
modified typing of while loops to allow other types than Unit (e.g. Unit
@cps). review by odersky.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 5cdc0f13c9..53970fc873 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1875,16 +1875,31 @@ trait Typers { self: Analyzer => case ldef @ LabelDef(_, _, _) => if (ldef.symbol == NoSymbol) ldef.symbol = namer.enterInScope( - context.owner.newLabel(ldef.pos, ldef.name) setInfo MethodType(List(), UnitClass.tpe)) + context.owner.newLabel(ldef.pos, ldef.name) setInfo MethodType(List(), NothingClass.tpe)) case _ => } } + private def isLoopHeaderLabel(name: Name): Boolean = + name.startsWith("while$") || name.startsWith("doWhile$") + def typedLabelDef(ldef: LabelDef): LabelDef = { - val restpe = ldef.symbol.tpe.resultType - val rhs1 = typed(ldef.rhs, restpe) - ldef.params foreach (param => param.tpe = param.symbol.tpe) - treeCopy.LabelDef(ldef, ldef.name, ldef.params, rhs1) setType restpe + if (!isLoopHeaderLabel(ldef.symbol.name) || phase.id > currentRun.typerPhase.id) { + val restpe = ldef.symbol.tpe.resultType + val rhs1 = typed(ldef.rhs, restpe) + ldef.params foreach (param => param.tpe = param.symbol.tpe) + treeCopy.LabelDef(ldef, ldef.name, ldef.params, rhs1) setType restpe + } else { + val rhs1 = typed(duplicateTree(ldef.rhs)) + val restpe = rhs1.tpe + context.scope.unlink(ldef.symbol) + val sym2 = namer.enterInScope( + context.owner.newLabel(ldef.pos, ldef.name) setInfo MethodType(List(), restpe)) + //val subst = new TreeSymSubstituter(List(ldef.symbol), List(sym2)) + val rhs2 = typed(ldef.rhs/*subst(ldef.rhs)*/, restpe) + ldef.params foreach (param => param.tpe = param.symbol.tpe) + treeCopy.LabelDef(ldef, ldef.name, ldef.params, rhs2) setSymbol sym2 setType restpe + } } protected def typedFunctionIDE(fun : Function, txt : Context) = {} @@ -3040,7 +3055,7 @@ trait Typers { self: Analyzer => } else { // An annotated term, created with annotation ascription // term : @annot() - def annotTypeTree(ainfo: AnnotationInfo): Tree = + def annotTypeTree(ainfo: AnnotationInfo): Tree = //TR: function not used ?? TypeTree(arg1.tpe.withAnnotation(ainfo)) setOriginal tree if (ann.tpe == null) { |