Skip to content

Instantly share code, notes, and snippets.

@Klasu
Last active August 29, 2015 14:05
Show Gist options
  • Save Klasu/100922f1204d003a03ba to your computer and use it in GitHub Desktop.
Save Klasu/100922f1204d003a03ba to your computer and use it in GitHub Desktop.
Scala 2.10 compiler crashes on the following code
import org.specs2.mutable.Specification
case class A(id: Int, created: String)
case class B(id: Int, aId: Int)
case class C(id: Int, created: String)
object ACreator {
val a = A(
id = 1,
created = "A"
)
}
object BCreator {
val b = B(
id = 1,
aId = 2
)
}
object CObject extends Specification {
def create(bId: Int, c: C) = {c}
}
class AFailure extends Specification {
val testC = C(id = 1, created = "C")
"A" should {
"fail" in {
val createdA = ACreator.a.copy(id = 2) // Giving this a type fixes the crash
val createdB = BCreator.b.copy(aId = createdA.id)
val created = CObject.create(createdB.id, testC) // Renaming the val created fixes the crash
created.id == 1
}
}
}
@Klasu
Copy link
Author

Klasu commented Aug 19, 2014

Changing the test to def foo = { val createdA... causes a compile error:

error: recursive value createdA needs type
val createdB = BCreator.b.copy(aId = createdA.id)

@Klasu
Copy link
Author

Klasu commented Aug 19, 2014

In Scala 2.11 this is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment