Permalink
Browse files

allow disabling patmat analyses: -Xno-patmat-analysis

  • Loading branch information...
adriaanm committed May 30, 2012
1 parent 9ebd4f9 commit 8cab2fa15f5fbd3ee319a224cb3a8ed80158a5ee
@@ -44,4 +44,5 @@ abstract class MutableSettings extends AbsSettings {
def maxClassfileName: IntSetting
def Xexperimental: BooleanSetting
def XoldPatmat: BooleanSetting
+ def XnoPatmatAnalysis: BooleanSetting
}
@@ -35,4 +35,5 @@ class Settings extends internal.settings.MutableSettings {
val Xexperimental = new BooleanSetting(false)
val deepCloning = new BooleanSetting (false)
val XoldPatmat = new BooleanSetting(false)
+ val XnoPatmatAnalysis = new BooleanSetting(false)
}
@@ -109,6 +109,7 @@ trait ScalaSettings extends AbsScalaSettings
val sourceReader = StringSetting ("-Xsource-reader", "classname", "Specify a custom method for reading source files.", "")
val XoldPatmat = BooleanSetting ("-Xoldpatmat", "Use the pre-2.10 pattern matcher. Otherwise, the 'virtualizing' pattern matcher is used in 2.10.")
+ val XnoPatmatAnalysis = BooleanSetting ("-Xno-patmat-analysis", "Don't perform exhaustivity/unreachability analysis. Also, ignore @switch annotation.")
/** Compatibility stubs for options whose value name did
* not previously match the option name.
@@ -1115,14 +1115,16 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
def isSwitchAnnotation(tpe: Type) = tpe hasAnnotation SwitchClass
def isUncheckedAnnotation(tpe: Type) = tpe hasAnnotation UncheckedClass
- val (unchecked, requireSwitch) = scrut match {
- case Typed(_, tpt) =>
- (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)
- case _ =>
- (false, false)
- }
+ val (unchecked, requireSwitch) =
+ if (settings.XnoPatmatAnalysis.value) (true, false)
+ else scrut match {
+ case Typed(_, tpt) =>
+ (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)
+ case _ =>
+ (false, false)
+ }
emitSwitch(scrut, scrutSym, casesNoSubstOnly, pt, matchFailGenOverride).getOrElse{
if (requireSwitch) typer.context.unit.warning(scrut.pos, "could not emit switch for @switch annotated match")

0 comments on commit 8cab2fa

Please sign in to comment.