Open
Description
Compiler version
3.6.3
Minimized code
class A:
protected class B
// This fails to compile, as expected
// val x = A().B()
object C:
protected val p = "protected"
protected def getString() = "Hello!"
protected class D
// This fails to compile
// val y = C.p
// And this also fails to compile
// val z = C.getString()
// However, this compiles just fine.
val alpha = C.D()
Output
The code compiles, even though a protected inner class is being accessed outside of the declaring object.
Expectation
I know that there isn't any point in declaring members of objects protected
, since an object can't be extended. However, the way that protected inner classes are handled (which, as far as I can tell, is to ignore the protected
keyword) is inconsistent with the way that protected vars/vals/defs are treated inside objects.