summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Typers.scala
diff options
context:
space:
mode:
authorTiark Rompf <tiark.rompf@epfl.ch>2010-02-10 14:21:57 +0000
committerTiark Rompf <tiark.rompf@epfl.ch>2010-02-10 14:21:57 +0000
commit96a7efb1fd7db67c21ff5000d343765c925a83d7 (patch)
tree60e2bf2c548c6cda3f485edecd06fbe2f9804264 /src/compiler/scala/tools/nsc/typechecker/Typers.scala
parent1c8210ec7e42139c62271edc513597befa288167 (diff)
downloadscala-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/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala27
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) {