Affects Version/s: Scala 2.9.2, Scala 2.10.0
Component/s: Misc Compiler
Mac OS X
java version "1.7.0_07"
Scala code runner version 2.9.2
Scala code runner version 2.10.0-20121011-125927-25ad7876a9
The inner function in the above code will be compiled into the following bytecode:
Needless to say, invokevirtual != goto. This was a silent failure of the tailrec optimization. No warnings were emitted by the compiler. This bug was found against 2.9.2 and later reproduced against a fresh build of the 2.10.0-RC1 tag.
Hilariously, removing the getOrElse 42 resolves the issue, and the compiler is able to compile the tail recursive call into a jump.
Given how pervasive this "@tailrec inner function" idiom is within the standard library, akka, and myriads of code bases (including Precog), this seems like a very serious issue. It basically implies that a lot of code that people think is safe will actually explode for sufficiently large datasets.