Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private Method isn't private #240

Open
felipetesc opened this issue Jul 24, 2018 · 4 comments
Open

Private Method isn't private #240

felipetesc opened this issue Jul 24, 2018 · 4 comments

Comments

@felipetesc
Copy link

felipetesc commented Jul 24, 2018

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!

@felipetesc
Copy link
Author

PS: I've used Gravity version 0.5.0.

@marcobambini
Copy link
Owner

Hi @felipetesc I should probably explain it better, but in the current implementation private means private from the outside and not from within the class itself.

@felipetesc
Copy link
Author

felipetesc commented Jul 24, 2018

Yes, I understood that previously, and I've used the function which the signature is private func get_public() from outside the class, inside the main func. Perhaps the previous example is confuse, so here it's another:

//file test test_am.gravity
class Test{
    private func getVal(){
        return "my string";
    }
}

//main.gravity
#include " test_am.gravity"
func main(){
    var test = Test();
    var val = test.getVal();// get val is a private method
    System.print(val);
}

When I execute gravity main.gravity I've got this result:
my string
RESULT: NULL (in 0.0338 ms)

@marcobambini
Copy link
Owner

@felipetesc seems like an issue that needs to be fixed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants