summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@typesafe.com>2015-05-06 07:50:11 +0200
committerLukas Rytz <lukas.rytz@typesafe.com>2015-05-06 07:50:11 +0200
commite12ba55589192fc3a3cc7b441569fbcabc04dd33 (patch)
tree391dcd89001d0a8d7eb1d862c8e558487483f828
parent8200009ea5dafcdf79488f19175c53e7b571aa75 (diff)
parent92f69d253ee6e941263aaf0a09936b4e4ce21dc7 (diff)
downloadscala-e12ba55589192fc3a3cc7b441569fbcabc04dd33.tar.gz
scala-e12ba55589192fc3a3cc7b441569fbcabc04dd33.tar.bz2
scala-e12ba55589192fc3a3cc7b441569fbcabc04dd33.zip
Merge pull request #4491 from som-snytt/issue/noassertions
SI-9302 -Xdisable-assertions raises elide level
-rw-r--r--src/compiler/scala/tools/nsc/settings/ScalaSettings.scala3
-rw-r--r--src/compiler/scala/tools/nsc/transform/UnCurry.scala4
-rw-r--r--src/library/scala/Predef.scala6
-rw-r--r--test/files/run/disable-assertions.flags1
-rw-r--r--test/files/run/disable-assertions.scala14
5 files changed, 21 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
index 630276e412..35ee889c58 100644
--- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
+++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
@@ -101,7 +101,8 @@ trait ScalaSettings extends AbsScalaSettings
val Xhelp = BooleanSetting ("-X", "Print a synopsis of advanced options.")
val checkInit = BooleanSetting ("-Xcheckinit", "Wrap field accessors to throw an exception on uninitialized access.")
val developer = BooleanSetting ("-Xdev", "Indicates user is a developer - issue warnings about anything which seems amiss")
- val noassertions = BooleanSetting ("-Xdisable-assertions", "Generate no assertions or assumptions.")
+ val noassertions = BooleanSetting ("-Xdisable-assertions", "Generate no assertions or assumptions.") andThen (flag =>
+ if (flag) elidebelow.value = elidable.ASSERTION + 1)
val elidebelow = IntSetting ("-Xelide-below", "Calls to @elidable methods are omitted if method priority is lower than argument",
elidable.MINIMUM, None, elidable.byName get _)
val noForwarders = BooleanSetting ("-Xno-forwarders", "Do not generate static forwarders in mirror classes.")
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
index 836ea808ac..1020b98bb9 100644
--- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala
+++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
@@ -437,9 +437,7 @@ abstract class UnCurry extends InfoTransform
def isLiftedLambdaBody(target: Tree) = target.symbol.isLocalToBlock && target.symbol.isArtifact && target.symbol.name.containsName(nme.ANON_FUN_NAME)
val result = (
- // TODO - settings.noassertions.value temporarily retained to avoid
- // breakage until a reasonable interface is settled upon.
- if ((sym ne null) && (sym.elisionLevel.exists (_ < settings.elidebelow.value || settings.noassertions)))
+ if ((sym ne null) && sym.elisionLevel.exists(_ < settings.elidebelow.value))
replaceElidableTree(tree)
else translateSynchronized(tree) match {
case dd @ DefDef(mods, name, tparams, _, tpt, rhs) =>
diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala
index 4eed672794..0f300412b7 100644
--- a/src/library/scala/Predef.scala
+++ b/src/library/scala/Predef.scala
@@ -35,9 +35,9 @@ import scala.io.StdIn
* === Assertions ===
*
* A set of `assert` functions are provided for use as a way to document
- * and dynamically check invariants in code. `assert` statements can be elided
- * at compile time by providing the command line argument `-Xdisable-assertions` to
- * the `scalac` command.
+ * and dynamically check invariants in code. Invocations of `assert` can be elided
+ * at compile time by providing the command line option `-Xdisable-assertions`,
+ * which raises `-Xelide-below` above `elidable.ASSERTION`, to the `scalac` command.
*
* Variants of `assert` intended for use with static analysis tools are also
* provided: `assume`, `require` and `ensuring`. `require` and `ensuring` are
diff --git a/test/files/run/disable-assertions.flags b/test/files/run/disable-assertions.flags
new file mode 100644
index 0000000000..afaa521a12
--- /dev/null
+++ b/test/files/run/disable-assertions.flags
@@ -0,0 +1 @@
+-Xdisable-assertions
diff --git a/test/files/run/disable-assertions.scala b/test/files/run/disable-assertions.scala
new file mode 100644
index 0000000000..7ec4cfb495
--- /dev/null
+++ b/test/files/run/disable-assertions.scala
@@ -0,0 +1,14 @@
+
+object Elided {
+ import annotation._, elidable._
+ @elidable(INFO) def info(): Boolean = true
+ @elidable(10000) def f(): Boolean = true
+ def g(): Boolean = { assert(false); true }
+}
+
+object Test extends App {
+ import Elided._
+ if (info()) println("Bad info.")
+ if (!f()) println("Elided f.")
+ if (!g()) println("Elided g?") // assert should be off
+}