summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-05-11 13:02:54 -0700
committerPaul Phillips <paulp@improving.org>2013-05-11 13:02:54 -0700
commitc663ecf8677eda3fe8c91170b614eb7166b18711 (patch)
tree80184e648c1f8c72f7e424649552425ceb51b19c /src/compiler
parent433880e91cba9e1e926e9fcbf04ecd4aeb1d73eb (diff)
downloadscala-c663ecf8677eda3fe8c91170b614eb7166b18711.tar.gz
scala-c663ecf8677eda3fe8c91170b614eb7166b18711.tar.bz2
scala-c663ecf8677eda3fe8c91170b614eb7166b18711.zip
Incorporated reviewer feedback.
Made things a little more consistent and self-apparent.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala21
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala16
2 files changed, 20 insertions, 17 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index fc1db32a2d..21c33aad0d 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -365,6 +365,7 @@ trait Contexts { self: Analyzer =>
@inline final def withinSuperInit[T](op: => T): T = withMode(enabled = SuperInit)(op)
@inline final def withinSecondTry[T](op: => T): T = withMode(enabled = SecondTry)(op)
@inline final def withinTypeConstructor[T](op: => T): T = withMode(enabled = TypeConstructor)(op)
+ @inline final def withinPatAlternative[T](op: => T): T = withMode(enabled = PatternAlternative)(op)
/* TODO - consolidate returnsSeen (which seems only to be used by checkDead)
* and ReturnExpr.
@@ -374,14 +375,8 @@ trait Contexts { self: Analyzer =>
withMode(enabled = ReturnExpr)(op)
}
- /** TODO: The "sticky modes" are EXPRmode, PATTERNmode, TYPEmode.
- * To mimick the sticky mode behavior, when captain stickyfingers
- * comes around we need to propagate those modes but forget the other
- * context modes which were once mode bits; those being so far the
- * ones listed here.
- */
- @inline final def withOnlyStickyModes[T](op: => T): T =
- withMode(disabled = PatternAlternative | StarPatterns | SuperInit | SecondTry | ReturnExpr | TypeConstructor | TypeApplication)(op)
+ // See comment on FormerNonStickyModes.
+ @inline final def withOnlyStickyModes[T](op: => T): T = withMode(disabled = FormerNonStickyModes)(op)
/** @return true if the `expr` evaluates to true within a silent Context that incurs no errors */
@inline final def inSilentMode(expr: => Boolean): Boolean = {
@@ -1389,6 +1384,16 @@ object ContextMode {
*/
final val TypeApplication: ContextMode = 1 << 17
+ /** TODO: The "sticky modes" are EXPRmode, PATTERNmode, TYPEmode.
+ * To mimick the sticky mode behavior, when captain stickyfingers
+ * comes around we need to propagate those modes but forget the other
+ * context modes which were once mode bits; those being so far the
+ * ones listed here.
+ */
+ final val FormerNonStickyModes: ContextMode = (
+ PatternAlternative | StarPatterns | SuperInit | SecondTry | ReturnExpr | TypeConstructor | TypeApplication
+ )
+
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 eeae7da94f..5cce4865cc 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -3039,7 +3039,7 @@ trait Typers extends Adaptations with Tags {
}
def typedArg(arg: Tree, mode: Mode, newmode: Mode, pt: Type): Tree = {
- val typedMode = mode stickyPlus newmode
+ val typedMode = mode.onlySticky | newmode
val t = withCondConstrTyper(mode.inSccMode)(_.typed(arg, typedMode, pt))
checkDead.inMode(typedMode, t)
}
@@ -3062,7 +3062,7 @@ trait Typers extends Adaptations with Tags {
// No formals left or * indicates varargs.
val isVarArgs = formals.isEmpty || formals.tail.isEmpty && isRepeatedParamType(formals.head)
val isByName = formals.nonEmpty && isByNameParamType(formals.head)
- def typedMode = mode stickyPlus ( if (isByName) NOmode else BYVALmode )
+ def typedMode = if (isByName) mode.onlySticky else mode.onlySticky | BYVALmode
def body = typedArg(args.head, mode, typedMode, adapted.head)
def arg1 = if (isVarArgs) context.withinStarPatterns(body) else body
@@ -4984,13 +4984,11 @@ trait Typers extends Adaptations with Tags {
newTyper(context.makeNewScope(ddef, sym)).constrTyperIf(isConstrDefaultGetter)
}
- def typedAlternative(alt: Alternative) = {
- val saved = context.inPatAlternative
- context.inPatAlternative = true
- try treeCopy.Alternative(tree, alt.trees mapConserve (alt => typed(alt, mode, pt))) setType pt
- finally context.inPatAlternative = saved
- }
-
+ def typedAlternative(alt: Alternative) = (
+ context withinPatAlternative (
+ treeCopy.Alternative(tree, alt.trees mapConserve (alt => typed(alt, mode, pt))) setType pt
+ )
+ )
def typedStar(tree: Star) = {
if (!context.starPatterns && !isPastTyper)
StarPatternWithVarargParametersError(tree)