Skip to content

Instantly share code, notes, and snippets.

@fedesilva
Created September 19, 2010 23:32
Show Gist options
  • Save fedesilva/587218 to your computer and use it in GitHub Desktop.
Save fedesilva/587218 to your computer and use it in GitHub Desktop.
Redefining companion kabooms
package caseclasses
case class A()
//This compiles Just Fine
object A
class Z {
def run(fun: => Unit) = fun
}
class Y extends Z {
case class B()
object B //This compiles Just Fine
run {
case class C()
//object C
//
//If I redefine C I get:
//src/main/scala/caseclasses.scala:30: C is already defined as (compiler-generated) case class companion object C
//[error] object C
//[error] ^
//[error] one error found
//
}
def method {
case class D()
//object D
//
//src/main/scala/caseclasses.scala:34: D is already defined as (compiler-generated) case class companion object D
//[error] object D
//[error] ^
//[error] one error found
}
}
@ebruchez
Copy link

ebruchez commented Oct 6, 2011

I hit the same issue. Is this in the Scala tracker?

@fedesilva
Copy link
Author

@ebruchez
Copy link

ebruchez commented Oct 6, 2011

Cool thanks. Just voted on the bug.

@fedesilva
Copy link
Author

The workaround iirc is to define the companion object first.

@ebruchez
Copy link

ebruchez commented Oct 6, 2011

I tried this but I get other compiler errors. For now I'll move this out of my method.

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