tags:

views:

49

answers:

1

Hi, I have a pair of loops over a nested array object in scala

def populateBoard(data:Array[Array[Char]]) {

    Board.resize(data(0).length, data.length)

    for(y <- 0 to data.length-1) {
        val row = data(y)
        for(x <- 0 to row.length-1) {
            Board.putObjectAt(x,y,GamePieceFactory.createInstance(row(x),x,y))
        }
    }

}

Which works just fine in the unit tests, but when I run the application I get the following exception:

java.lang.NoSuchMethodError: scala.runtime.RichInt.to(I)Lscala/Range;
at net.ceilingfish.pacman.App$.populateBoard(App.scala:37)

Line 37 is the line for(y <- 0 to data.length-1). Very odd. The unit tests run scala 2.6.1 and the command line is 2.7.7. Are there some backward incompatible changes between these two versions?

UPDATE I switched the unit tests to version 2.7.7 and they carried on working just fine. Even odder.

+2  A: 

Scala is not typically binary compatible between versions. In particular, this means that if you compile for 2.6.1 and then try to run for 2.7.7, even if the syntax has not changed at all, the libraries almost certainly have and thus you may run into errors. I would suspect that you're not running with the same version you're compiling with.

Also, you may wish to use 0 until n rather than 0 to n - 1.

Rex Kerr
Switching to `until` seemed to fix the problem! Thanks!
Ceilingfish