Skip to content

Instantly share code, notes, and snippets.

@retronym
Created December 10, 2009 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retronym/253684 to your computer and use it in GitHub Desktop.
Save retronym/253684 to your computer and use it in GitHub Desktop.
Limitations of Early Definitions, a new feature in Scala 2.8
trait Base {
val abstractVal: String
final val useAbstractVal = abstractVal
}
{
class C1 extends Base {
val abstractVal = "C1.abstractVal"
}
assert(new C1().useAbstractVal eq null)
}
{
class C2 extends {
val abstractVal = "C2.abstractVal"
} with Base
assert(new C2().useAbstractVal == "C2.abstractVal")
}
{
trait T1 extends {
val abstractVal = "T1.abstractVal"
} with Base
class C3 extends T1
assert(new C3().useAbstractVal eq null) // why not == "T1.abstractVal" ?
}
{
class T2 extends {
val abstractVal = "T2.abstractVal"
} with Base
case object O1 extends T2
assert(O1.useAbstractVal == "T2.abstractVal")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment