Monday, November 8, 2010

Scala & Eclipse...Just keep cleaning...

Today's aggravation is most likely brought to you by the Scala IDE (v1.0.0.201009232358) plugin for Eclipse (v3.5.2.R35).  A simplified version of the offending code is:
  def nestedDoesntWork(num: Int) = {
    if (true)
      for (x <- 0 until num)
        println(x)
  }

Where I have some condition that is checked and if true, proceeds into a for-loop.  The error that I repeatedly get is:
  • Exception in thread "main" java.lang.NoSuchMethodError: scala.collection.immutable.Range$ByOne.foreach$mVc$sp(Lscala/Function1;)V
        at org.spin.node.gogrid.Client$.doesntWork(Client.scala:62)
        at org.spin.node.gogrid.Client$.main(Client.scala:72)
        at org.spin.node.gogrid.Client.main(Client.scala)
However, this seems to work:
  def nestedWorks(num: Int) = {
    if (true)
      for (x <- (0 until num).toList)
        println(x)
  }

Very odd. Even odder is if I define either of these functions on the Scala interpreter in Eclipse, they work fine. It's only when the nestedDoesntWork is defined within a class and I try to run a main function calling that class. The same happens if I take out the if(true) line.

Solution? Clean project...and look, everything is fine and dandy. Make a change, get the error? Clean the project, and hurray.  Note that the nestedWorks always works...without cleaning.

Annoying to say the least, but today's lesson is if it doesn't work when it should the first time, clean the project.  If it still doesn't work, clean it again. and again. and again.

No comments:

Post a Comment