Skip to content

Private Method isn't private #240

@felipetesc

Description

@felipetesc

Hello there. I was writing some examples to test and document the access modifiers and I found that the code below works:

class TestAccessModifiers{
    public var my_var = "I'm public!";
    private var my_hidden_var = "I'm private!";
    public func get_hidden(){
        return my_hidden_var;
    }
    private func get_public(){
        return my_var;
    }
}
func puts(str){
    System.print(str);
}
func main(){
    var test = TestAccessModifiers();
    test.my_var;
    //puts("Public var holds = " + test.my_var );//works
    //puts("Get hidden var from public method = " + test.get_hidden());//works
    //puts("Private var holds = " + test.my_hidden_var );//works and cause error like it should
    puts("Get public var from private method = " + test.get_public());//doesn't works 

}

As result, from the terminal, I get :
Get public var from private method = I'm public!
I donno, but I guessing that the keyword private before the keyword func should print the same, or almost the same value, as in "puts("Private var holds = " + test.my_hidden_var );", which is :: RUNTIME ERROR: Unable to find my_hidden_var into class TestAccessModifiers

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions