Skip to content

Commit

Permalink
allow disabling patmat analyses: -Xno-patmat-analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
adriaanm committed Jun 1, 2012
1 parent 9ebd4f9 commit 8cab2fa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ abstract class MutableSettings extends AbsSettings {
def maxClassfileName: IntSetting
def Xexperimental: BooleanSetting
def XoldPatmat: BooleanSetting
def XnoPatmatAnalysis: BooleanSetting
}
1 change: 1 addition & 0 deletions src/compiler/scala/reflect/runtime/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 10 additions & 8 deletions src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 8cab2fa

Please sign in to comment.