7

Is there a way to run a Scala application or unit test within the Scala IDE 2.0.2 (Eclipse 3.7) if there are (unrelated!) compilation errors in the project?

In Java, this is no problem, but Scala IDE keeps telling me:

Project contains compilation errors (therefore, no binaries have been produced).

All I want to do is to run a small test during a major refactoring process, but I can't fix all compilation errors right now. And I don't want to start commenting things out, as those compilation errors are good reminders of tasks that still need to be done.

rolve
  • 9,021
  • 4
  • 50
  • 70

2 Answers2

4

Currently the Scala IDE does not support this behavior, but it would be nice if it could.

To be aware of this, I created a ticket:

JDT allows to execute Java code despite of compilation problems in the sources. Internally JDT replaces the defective code with an exception, which is thrown if the relevant code is executed. But if the defective code is never called during execution, nothing bad happens. It would be nice if SDT supports similar behavior.

rolve
  • 9,021
  • 4
  • 50
  • 70
kiritsuku
  • 51,545
  • 18
  • 109
  • 133
  • Interesting, I didn't know that JDT has to do something like this to support that feature. I thought it somehow executes the program completely excluding the erroneous classes from the classpath. But this makes more sense. Thanks for the ticket and the explanations. – rolve Nov 01 '12 at 15:16
1

If you are using Scala 2.10, a good option is to use the newly introduced ??? notation. This way your code will compile even if the function is not yet implemented.

There is certainly a better way but this one will still be better than commenting code.

As suggested by Jesper, you can still implement ??? if you are working with previous versions of Scala:

def ??? : Nothing = throw new Error("Not implemented") 
Christopher Chiche
  • 14,409
  • 9
  • 55
  • 94
  • Thanks, but I'm kind of forced to use Scala 2.9.2. – rolve Nov 01 '12 at 14:20
  • 2
    @rolve Note that `???` is not a new keyword or a change to the language. You can easily program it yourself: `def ???: Nothing = throw new Error("Not implemented")` (This is what's done in the Coursera Scala course). – Jesper Nov 01 '12 at 15:36
  • Thanks for the clarification! – Christopher Chiche Nov 01 '12 at 16:07
  • 1
    @Jesper Thanks. Just one small note: I think the correct declaration is `def ??? : Nothing = throw new Error("Not implemented")` with a space after `???`. Without the space, it doesn't compile. – rolve Nov 01 '12 at 16:22