Skip to content

Instantly share code, notes, and snippets.

@eboto
Created October 5, 2012 22:08
Show Gist options
  • Save eboto/3842725 to your computer and use it in GitHub Desktop.
Save eboto/3842725 to your computer and use it in GitHub Desktop.
A doozy of a compiler crash we saw at Egraphs
// This example produces a compiler error in Scala 2.9.1 and 2.9.2. It works fine in Scala 2.10M7.
// The error text is: "java.lang.Error: symbol value blobKey does not exist in Crasher$$anonfun$1.apply"
object Crasher {
def main(args: Array[String]) {
println("This will never be printed because the compiler will crash")
}
}
class Crasher { // this can be a trait, class, object, whatever
def filter = new Filter // has to be a def
// have to use the default args for first param list ---v
def testForFailure(blobKey: String) = filter() {
Result {
// v-- this has to be an assignment. Do anything you want with blobKey and it will fail
val thisAssignmentCrashes = if (blobKey == null) "herp" else "derp"
"herp derp" // return whatever you want
}
}
}
// The key here is that it's parameterized I think.
abstract class Result[+T] {
def instance: T
}
object Result {
// operation could be a by-name parameter or a function
def apply[T](operation: => T): Result[T] = {
new Result[T] {
def instance = operation
}
}
}
class Filter() {
// Has to have default args
def apply[A](openDatabase: Boolean = false)(operation: Result[A]): Result[A] = {
Result {
operation.instance
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment