I have a type hierarchy like this:
trait Description {
}
trait DescriptionProvider {
val description: Description
}
object Sample extends DescriptionProvider {
object description extends Description {
val name = "foo"
}
}
f
a.description
DescriptionProvider
f(Sample).name
foo
def obvious[T <: DescriptionProvider](x: T) = x.description
obvious(Sample).name // doesn't compile of course, as foo returns only Description.
.name
Annotate your return type with a path-dependent one instead of relying on inference:
def obvious[T <: DescriptionProvider](x: T): x.description.type = x.description
I made a Scastie snippet with 2.10.6 and it seems to be working. I cannot check if Intellij would not complain, however.