I would like to qualify a method of an inner trait so that it can only be accessed by subclasses of the outer trait. E.g.:
trait Tree[A] {
trait TNode {
final def prevOption: Option[TNode] = Option(prev)
protected[Tree] def prev: TNode // !
}
def test(n: TNode): Option[TNode] = Option(n.prev)
}
How can I modify the qualifiers of prev, so that the following does compile:
trait TreeImpl[A] extends Tree[A] {
def test2(n: TNode): Option[TNode] = Option(n.prev)
}
While this does not compile:
def test3[A](t: Tree[A]#TNode) = t.prev
(that is to say, a public def prev: TNode is not an option).
It seems as if this is not possible.
A possible workaround is a protected accessor method on Tree, like so (I removed some stuff, to make code clearer):