Run Scala application in Scala IDE with compilation errors
Asked Answered
H

2

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.

Haughty answered 1/11, 2012 at 14:6 Comment(0)
S
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.

Sporozoite answered 1/11, 2012 at 14:50 Comment(1)
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.Haughty
I
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") 
Incommodity answered 1/11, 2012 at 14:17 Comment(3)
Thanks, but I'm kind of forced to use Scala 2.9.2.Haughty
@Haughty 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).Mate
@Mate 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.Haughty

© 2022 - 2024 — McMap. All rights reserved.