summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala9
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala6
-rw-r--r--src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala4
-rw-r--r--src/reflect/scala/reflect/internal/Mode.scala5
4 files changed, 14 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index dc75fa3746..48df7cb261 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -243,6 +243,7 @@ trait Contexts { self: Analyzer =>
def retyping = this(ReTyping)
def inSecondTry = this(SecondTry)
def inSecondTry_=(value: Boolean) = this(SecondTry) = value
+ def inReturnExpr = this(ReturnExpr)
/** These messages are printed when issuing an error */
var diagnostic: List[String] = Nil
@@ -361,6 +362,11 @@ trait Contexts { self: Analyzer =>
def withSuperInit[T](op: => T): T = withMode(enabled = SuperInit)(op)
def withSecondTry[T](op: => T): T = withMode(enabled = SecondTry)(op)
+ def withReturnExpr[T](op: => T): T = {
+ enclMethod.returnsSeen = true
+ withMode(enabled = ReturnExpr)(op)
+ }
+
/** @return true if the `expr` evaluates to true within a silent Context that incurs no errors */
@inline final def inSilentMode(expr: => Boolean): Boolean = {
withMode() { // withMode with no arguments to restore the mode mutated by `setBufferErrors`.
@@ -1355,6 +1361,9 @@ object ContextMode {
*/
final val SecondTry: ContextMode = 1 << 14
+ /** Are we in return position? Formerly RETmode. */
+ final val ReturnExpr: ContextMode = 1 << 15
+
final val DefaultMode: ContextMode = MacrosEnabled
private val contextModeNameMap = Map(
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 2066ab980d..3bcc670c89 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -4292,9 +4292,9 @@ trait Typers extends Adaptations with Tags {
val DefDef(_, name, _, _, restpt, _) = enclMethod.tree
if (restpt.tpe eq null) {
ReturnWithoutTypeError(tree, enclMethod.owner)
- } else {
- context.enclMethod.returnsSeen = true
- val expr1: Tree = typed(expr, EXPRmode | BYVALmode | RETmode, restpt.tpe)
+ }
+ else {
+ val expr1 = context withReturnExpr typed(expr, EXPRmode | BYVALmode, restpt.tpe)
// Warn about returning a value if no value can be returned.
if (restpt.tpe.typeSymbol == UnitClass) {
// The typing in expr1 says expr is Unit (it has already been coerced if
diff --git a/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala b/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala
index 519b90f0c6..e6153596f7 100644
--- a/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala
+++ b/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala
@@ -169,7 +169,7 @@ abstract class CPSAnnotationChecker extends CPSUtils {
true
//}
} else false
- } else if (!hasPlusMarker(tree.tpe) && annots1.isEmpty && !annots2.isEmpty && mode.inRetMode) {
+ } else if (!hasPlusMarker(tree.tpe) && annots1.isEmpty && !annots2.isEmpty && typer.context.inReturnExpr) {
vprintln("checking enclosing method's result type without annotations")
tree.tpe <:< pt.withoutAnnotations
} else if (!hasMinusMarker(tree.tpe) && !annots1.isEmpty && mode.inByValMode) {
@@ -219,7 +219,7 @@ abstract class CPSAnnotationChecker extends CPSUtils {
val res = tree modifyType addMinusMarker
vprintln("adapted annotations (by val) of " + tree + " to " + res.tpe)
res
- } else if (mode.inRetMode && !hasPlusMarker(tree.tpe) && isMissingExpectedAnnots) {
+ } else if (typer.context.inReturnExpr && !hasPlusMarker(tree.tpe) && isMissingExpectedAnnots) {
// add a marker annotation that will make tree.tpe behave as pt, subtyping wise
// tree will look like having any possible annotation
diff --git a/src/reflect/scala/reflect/internal/Mode.scala b/src/reflect/scala/reflect/internal/Mode.scala
index 89d6be0248..a15a3dcc84 100644
--- a/src/reflect/scala/reflect/internal/Mode.scala
+++ b/src/reflect/scala/reflect/internal/Mode.scala
@@ -71,10 +71,6 @@ object Mode {
*/
final val TYPEPATmode: Mode = 0x10000
- /** RETmode is set when we are typing a return expression.
- */
- final val RETmode: Mode = 0x20000
-
final private val StickyModes: Mode = EXPRmode | PATTERNmode | TYPEmode
/** Translates a mask of mode flags into something readable.
@@ -129,7 +125,6 @@ final class Mode private (val bits: Int) extends AnyVal {
def inPatternMode = inAll(PATTERNmode)
def inPolyMode = inAll(POLYmode)
def inQualMode = inAll(QUALmode)
- def inRetMode = inAll(RETmode)
def inSccMode = inAll(SCCmode)
def inTappMode = inAll(TAPPmode)
def inTypeMode = inAll(TYPEmode)