This looks like a bug to me (at least in 2.8.0 Beta1, where I tested it).
Particularly instructive is the following:
scala> var x: SampleEnum.type#Value = null x: SampleEnum.Value = null
Here we request an arbitrary internal type, but actually get a specific internal type. This is just broken (and I will write a bug report if it is not there already, unless someone quickly explains why it is not a mistake).
So what to do? Well, first, let's understand the original signature of the parse method:
def parse[T <: Enumeration](name:String, enum:T):T#Value
We have T , which is a subclass of Enumeration , enum , which is an instance of T , and - since there is no way to express that Value must be from this particular instance of T , we must resort to T#Value (i.e., the internal type T , regardless of which T it comes from).
Now we need to transfer a specific object, return the general internal object and make it in the face of ExampleObject.type#Value equal to ExampleObject.Value , even if they are printed in different ways.
So, we have to write our own object from scratch:
class SampleWorkaroundClass extends Enumeration { val include, exclude = Value } lazy val SampleWorkaround = new SampleWorkaroundClass
Here we have one instance of a specially defined class. Now we can get around the error in Object :
scala> val typeWorks:SampleWorkaroundClass#Value = parse("include",SampleWorkaround) typeWorks: SampleWorkaroundClass#Value = include
( lazy val is to get the same behavior as with objects where they are not created until they are used, but only val will be.)
Edit: Outer#Inner means "any inner class of type Inner originating from this outer class", unlike myOuter.Inner , which means "only the class of type Inner that has this Outer instance, myOuter , as its spanning class." Also, I am not getting a dependent type error in 2.8.0 Beta1 - but the inability to specify the type makes things pretty uncomfortable.
Edit: refresh the error report - the way it works now is obviously intentional. To use types in this way, you must explicitly specify the type of function call (since this is not displayed the way you want), e.g.
val suggested: SampleEnum.type#Value = parse[SampleEnum.type]("include",SampleEnum)
This method is easier if you need to do this several times. If you need to do this many times, creating your own class using val (or lazy val) may make things simpler / simpler.