summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2012-06-05 17:41:47 +0200
committerEugene Burmako <xeno.by@gmail.com>2012-06-08 15:35:04 +0200
commit10292e4acbb8eb0143a5a087c750ed9699f31807 (patch)
tree894a8cc7feda82bf802bdfa556a0fe41c21bf2d2 /src
parentb31c6d4f778df6b415c605a468b155cea0b84a16 (diff)
downloadscala-10292e4acbb8eb0143a5a087c750ed9699f31807.tar.gz
scala-10292e4acbb8eb0143a5a087c750ed9699f31807.tar.bz2
scala-10292e4acbb8eb0143a5a087c750ed9699f31807.zip
de-duplicate isUncheckedAnnotation/isSwitchAnnotation
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala7
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala7
-rw-r--r--src/reflect/scala/reflect/internal/TreeInfo.scala6
3 files changed, 10 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
index 6d6430207d..1b8513373d 100644
--- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
+++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
@@ -410,18 +410,15 @@ abstract class ExplicitOuter extends InfoTransform
(CASE(transform(strippedPat)) IF gdcall) ==> transform(body)
}
- def isUncheckedAnnotation(tpe: Type) = tpe hasAnnotation UncheckedClass
- def isSwitchAnnotation(tpe: Type) = tpe hasAnnotation SwitchClass
-
val (checkExhaustive, requireSwitch) = nselector match {
case Typed(nselector1, tpt) =>
- val unchecked = isUncheckedAnnotation(tpt.tpe)
+ val unchecked = treeInfo.isUncheckedAnnotation(tpt.tpe)
if (unchecked)
nselector = nselector1
// Don't require a tableswitch if there are 1-2 casedefs
// since the matcher intentionally emits an if-then-else.
- (!unchecked, isSwitchAnnotation(tpt.tpe) && ncases.size > 2)
+ (!unchecked, treeInfo.isSwitchAnnotation(tpt.tpe) && ncases.size > 2)
case _ =>
(true, false)
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
index eb77ec8224..68522c727f 100644
--- a/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
@@ -1110,16 +1110,13 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
def matchFailGen = (matchFailGenOverride orElse Some(CODE.MATCHERROR(_: Tree)))
// patmatDebug("combining cases: "+ (casesNoSubstOnly.map(_.mkString(" >> ")).mkString("{", "\n", "}")))
- def isSwitchAnnotation(tpe: Type) = tpe hasAnnotation SwitchClass
- def isUncheckedAnnotation(tpe: Type) = tpe hasAnnotation UncheckedClass
-
val (unchecked, requireSwitch) =
if (settings.XnoPatmatAnalysis.value) (true, false)
else scrut match {
case Typed(_, tpt) =>
- (isUncheckedAnnotation(tpt.tpe),
+ (treeInfo.isUncheckedAnnotation(tpt.tpe),
// matches with two or fewer cases need not apply for switchiness (if-then-else will do)
- isSwitchAnnotation(tpt.tpe) && casesNoSubstOnly.lengthCompare(2) > 0)
+ treeInfo.isSwitchAnnotation(tpt.tpe) && casesNoSubstOnly.lengthCompare(2) > 0)
case _ =>
(false, false)
}
diff --git a/src/reflect/scala/reflect/internal/TreeInfo.scala b/src/reflect/scala/reflect/internal/TreeInfo.scala
index 4b2105876d..698d219634 100644
--- a/src/reflect/scala/reflect/internal/TreeInfo.scala
+++ b/src/reflect/scala/reflect/internal/TreeInfo.scala
@@ -326,6 +326,12 @@ abstract class TreeInfo {
case _ => false
}
+ /** a Match(Typed(_, tpt), _) is unchecked if isUncheckedAnnotation(tpt.tpe) */
+ def isUncheckedAnnotation(tpe: Type) = tpe hasAnnotation definitions.UncheckedClass
+
+ /** a Match(Typed(_, tpt), _) must be translated into a switch if isSwitchAnnotation(tpt.tpe) */
+ def isSwitchAnnotation(tpe: Type) = tpe hasAnnotation definitions.SwitchClass
+
/** can this type be a type pattern */
def mayBeTypePat(tree: Tree): Boolean = tree match {
case CompoundTypeTree(Template(tps, _, Nil)) => tps exists mayBeTypePat