Type aliasing a case class in Scala 2.10

scala

Solution

When you create a case class Scala automatically creates a companion object for it. In your code you define an alias for the type `Thing`, i.e. for the class `Thing` only. Your companion object `Thing` still has only 1 name and no aliases.

One way to "fix" it is to create a reference to the companion object (not a type alias) like this:

scala> val Bar = Thing
Bar: Thing.type = Thing

scala> Bar("a", "b")
res1: Thing = Thing(a,b)

Another way to "fix" it would be to rename the imported object with `import package.{Thing => Bar}`.

Problem

I'm using Scala 2.10.2, and have two case classes that have identical fields: ``` case class Foo(id: String, name: String) case class Bar(id: String, name: String) ``` I'd like to do something like this: ``` case class Thing(id: String, name: String) type Foo = Thing type Bar = Thing ``` This compiles, but when I try to create a `Foo`, I get: ``` scala> Bar("a", "b") <console>:8: error: not found: value Bar Bar("a", "b") ^ ``` Does type aliasing not work with case classes?

Original source