In Scala 2.9.1 I get the following behavior:
class Foo {
case class X()
object X // this compiles
def bar() {
object Y // this compiles
case class Y()
case class Z()
object Z // won't compile (see below)
}
}
The compiler complains for Object Z
:
error: Z is already defined as (compiler-generated) case class companion object Z
It looks as if it is not permissible to define a companion object for a case class after the case class definition if they are within a function definition. Is this a compiler bug, or intentional? If the latter, why?