E173: Cannot Be Accessed
This error occurs when trying to access a member that is not visible due to access modifiers (private, protected, etc.) from the current scope.
Scala's access modifiers control which code can access which members. Private members can only be accessed from within the defining class, while protected members can be accessed from subclasses.
Example
class Secret {
private def hidden = 42
}
def test = {
val s = new Secret
s.hidden
}
Error
-- [E173] Reference Error: example.scala:7:4 -----------------------------------
7 | s.hidden
| ^^^^^^^^
|method hidden cannot be accessed as a member of (s : Secret) from the top-level definitions in package <empty>.
| private method hidden can only be accessed from class Secret.
Solution
class Secret {
private def hidden = 42
// Expose via a public method
def revealed: Int = hidden
}
def test = {
val s = new Secret
s.revealed
}
// Or change the access modifier
class Secret {
def visible = 42
}
def test = {
val s = new Secret
s.visible
}
In this article