E06180: not accessible from this context
What went wrong
You're trying to use a method, property or constructor that EXISTS but is NOT ACCESSIBLE from your current context due to visibility rules (private/protected).
A common case is a dynamic function or class BODY naming a property of the object around it (or a capture of an enclosing dynamic function). A dynamic construct is not inside that object, so its body cannot reach the object's properties directly - they are reached through a CAPTURE. The capture list is evaluated in the method that creates the dynamic construct, where the property is visible:
above() <- rtn as Predicate of Integer: (limit: pivot) is Predicate of Integer as pure function r: t > limit
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 2130 (Can a dynamic function created in a method capture the class's own private property, and does it share it?)
- ek9 -q 2131 (How does a dynamic function take a class property as a starting value without changing the property?)
- ek9 -q 95 (How do I control field visibility in EK9?)
- ek9 -q 97 (What is the difference between classes and records in EK9?)
- ek9 -q 93 (How do I define a class in EK9?)
- ek9 -q 118 (How do I implement the builder pattern in EK9?)
How to fix it
In a dynamic function or class body:
- Capture the property - '(limit: pivot)' - and use the capture. It SHARES the object: a mutation ('++', '+=', a copy into it) of 'limit' moves 'pivot'. Choose this when the dynamic construct exists to update the object (a callback recording into its tally).
- Capture a copy - '(limit: Integer(pivot))' - when the dynamic construct only needs an initial value it then works on; 'pivot' does not move.
Elsewhere:
- Make method public if external access is needed
- Create public wrapper method that calls private method
- Extend the class to access protected methods
- Check if there's an alternative public API
Common causes
- A dynamic function/class body naming the enclosing object's property instead of a capture of it
- Accessing private method or property from outside the class
- Accessing a super class's private property from a subclass (a capture of it is judged the same way)
- Accessing protected method from non-subclass
- Accessing internal method from different module
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E06180: not accessible from this context
#!ek9 defines module error.e06180.bad defines class Account as open balance as Integer: 0 default private Account() Account() -> opening as Integer balance: opening protected adjust() -> amount as Integer balance += amount private audit() <- rtn as Boolean: balance >= 0 default operator ? Savings extends Account Savings() //The no-argument constructor is private to Account super() check() <- rtn as Boolean? //A private method is not visible to a sub-type rtn: audit() default operator ? Auditor correct() -> account as Savings //A protected method is visible only within the hierarchy account.adjust(1) Splitter pivot as Integer: 10 above() //A dynamic function's body is not inside Splitter: it cannot name pivot <- rtn as Predicate of Integer: () is Predicate of Integer as pure function r: t > pivot default operator ?
Fixed: Call what is visible from where you are: a public constructor, a protected method, a captured value
#!ek9 defines module error.e06180.good.fix defines class Account as open balance as Integer: 0 default private Account() Account() -> opening as Integer balance: opening adjust() -> amount as Integer balance += amount protected audit() <- rtn as Boolean: balance >= 0 default operator ? Savings extends Account Savings() //The no-argument constructor is private to Account super(0) check() <- rtn as Boolean? //A private method is not visible to a sub-type rtn: audit() default operator ? Auditor correct() -> account as Savings //A protected method is visible only within the hierarchy account.adjust(1) Splitter pivot as Integer: 10 above() //A dynamic function's body is not inside Splitter: it cannot name pivot <- rtn as Predicate of Integer: (pivot) is Predicate of Integer as pure function r: t > pivot default operator ?
Fixed: Call what the context can see: a public constructor, a protected method from the sub-type, and capture the property
#!ek9 defines module error.e06180.good defines class Account as open balance as Integer: 0 default private Account() Account() -> opening as Integer balance: opening protected audit() <- rtn as Boolean: balance >= 0 adjust() -> amount as Integer balance += amount default operator ? Savings extends Account Savings() super(0) check() <- rtn as Boolean: audit() default operator ? Auditor correct() -> account as Savings account.adjust(1) Splitter pivot as Integer: 10 //The capture list is evaluated in above(), where pivot is visible above() <- rtn as Predicate of Integer: (limit: pivot) is Predicate of Integer as pure function r: t > limit default operator ?
Questions and answers
These Q&A entries show E06180 and its fix:
- Q93: How do I define a class in EK9?
- Q95: How do I control field visibility in EK9?
- Q97: What is the difference between classes and records in EK9?
- Q101: Why are types closed by default in EK9?
- Q118: How do I implement the builder pattern in EK9?
- Q119: What EK9 constructs are available and when should I use each?
- Q128: Why can't I extend List or Dict in EK9?
- Q682: How does field encapsulation work in generic classes?
- Q900: What is the difference between record and class field visibility in EK9?
- Q992: Review this EK9 class. Does it follow EK9 best practices?
- Q1231: Find the nearest Waypoint from two optional locations using <? on a class with distance.
- Q1348: What are the two safe ways to write a generic class that has an optional 'T?' field?
- Q2130: Can a dynamic function created in a method capture the class's own private property, and does it share it?
Found a problem?
If EK9 reported E06180 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.