2

I want to work with assertions in a Scala program. The assertions should be turned off for the final version of the program for increasing the performance.

There seem to be two Scala compiler flags enabling this (the first one requires an additional priority):

-Xelide-below
-Xdisable-assertions

However, activating those in the Scala Compiler Properties of my Scala project in Eclipse has no effect: the assertions are still executed.

The small program I used for testing:

object Test {
  def main(args: Array[String]): Unit = {
    assert(false) 
  }
}

I made sure the code is recompiled; I tested different (very high) priorities for -Xelide-below.

I use Eclipse Juno (4.2.0) and the Scala Plugi-In 2.1.0.nightly-2_09-201209040315-cc63a95 together with Scala 2.9.1-1 on a Windows 7 machine.

kiritsuku
  • 52,967
  • 18
  • 114
  • 136
fbeck
  • 153
  • 4

1 Answers1

4

To disable assertions you should use Scala Compiler > Advanced > Xdisable-assertions.

Another way to disable them is to pass the option -Xdisable-assertions to Scala Compiler > Additional command line parameters

kiritsuku
  • 52,967
  • 18
  • 114
  • 136
  • Thanks, it works! I only tried the exact same thing in the project settings, but it had no effect. If I change it in the global settings as proposed instead, it works. Very funny, maybe a bug? – fbeck Sep 08 '12 at 09:53
  • @fbeck: Yes it seems to be a bug. I reported it [here](https://www.assembla.com/spaces/scala-ide/tickets/1001241). – kiritsuku Sep 08 '12 at 10:20
  • Can the same effect be achieved with JVM arguments like in Java? – pedrofurla Sep 08 '12 at 16:03
  • 1
    @pedrofurla: Not, not with JVM args. Scala assertions are deleted at compile time not at runtime (as Java assertions). – kiritsuku Sep 08 '12 at 16:46
  • I know about the @elidable, but for some reason I assumed that at least some of the assertions would be compiled to the same bytecode as Java ones. – pedrofurla Sep 08 '12 at 16:59