Ticket Created
over 3 years ago

WERETECH-12014

Object-private vs Class-private

In the doc it says:

"The private modifier specifies that the member can only be accessed in its own CLASS"

1) https://developer.garmin.com/connect-iq/monkey-c/objects-and-memory/  -> "Data Hiding"

2) https://developer.garmin.com/connect-iq/reference-guides/monkey-c-reference/#datahiding

However, I'm unable to access private members in a static function of the same Class:

class A {
    private var _member;
    
    public function initialize(){
        
    }
    
    public function calcMember(){
        _member = doSomeFancyCalculation();
    }
    
    public static function createFromStorage() as A {
        var newA = new A();
        
        // Error: Symbol Not Found Error
        // Details: Could not find symbol '_member'
        newA._member = Storage.getValue("key_storedMember");
        
        return newA;
    }
}


So unless this is something you wanna fix in the language to align with the docs and e.g. Java or C++, you should at least update the doc to correctly reflect the current behavior.
Without having tested it, I would assume that there's a similar issue with the protected-Keyword.

Corresponding forum thread with code sample:
https://forums.garmin.com/developer/connect-iq/f/discussion/279953/implementation-of-the-private-keyword#pifragment-702=2

SDK: connectiq-sdk-lin-4.0.6-2021-10-06-af9b9d6e2
Device: Simulator (fr945)