scala> trait X { private[this] type A = Int; def a: A = 1 }
defined trait X
The access restrictions correctly prevent me from accessing the type
member from outside of `x`.
scala> type xA = x.A
<console>:10: error: type A is not a member of java.lang.Object with X
type xA = x.A
^
scala> val x = new X {}
x: java.lang.Object with X = $anon$1@58bf7b3e
scala> x.a
res6: Int = 1
But I can see the type in the eta-expanded signature here:
scala> x.a _
res7: () => x.A = <function0>
Not sure if this is a problem, it just strikes me as a bit odd to
allow private type members to appear in public signatures, by contrast
with the way private template definitions are handled.
scala> trait X { private[this] trait A; def a: A = null }
<console>:8: error: private trait A escapes its defining scope as
part of type X.this.A
trait X { private[this] trait A; def a: A = null }
^
Any insights into the distinction?
Thanks,
-jason
Any insights into the distinction?
What's your diagnosis with protected, rather than private? That's
actually the case I found in the wild that prompted my investigations.
GridGain's Scala API contains:
class ScalarCacheProjection[K, V](private val impl:
GridCacheProjection[K, V]) extends
Iterable[GridCacheEntry[K, V]] {
assert(impl != null)
protected type Projection = K GridCacheProjection V
// ...
def update(k: K, v: V): Projection = {
impl.putx(k, v)
impl
}
}