-
-
Notifications
You must be signed in to change notification settings - Fork 23.5k
Reimplement soft access restriction for members prefixed with _
#103768
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
base: master
Are you sure you want to change the base?
Reimplement soft access restriction for members prefixed with _
#103768
Conversation
|
I do really like this warning, but I wouldn't use it unless I could suppress the warning for a single line. Is that possible with the current code analysis system? |
|
As for the bug, "no warning when the current class has the same private member as the accessed class that is not the super class of the current class", this is because the method if (parser->current_class->has_member(p_identifier->name)) {
return;
}For example, if A and B has the same signatured function, while they are not derived from the other one: class A:
var _t := 1
class B:
var a := A.new()
var _t := 2
func _init() -> void:
a._t = 3 # No warning as B has a member with the same name `_t`Dunno how to deal with this as during reduction you cannot infer the details of the subscript base, except its type and name. |
You can ignore the warning with |
af64759 to
c04e9aa
Compare
|
Everything is now ready for review :D |
7d91178 to
8636116
Compare
|
I really like this change! Having the option for Godot to throw errors when accessing private members and methods helps a lot. |
8636116 to
1ec9c52
Compare
| return R"("@onready" will set the default value after "@export" takes effect and will override it.)"; | ||
| case ACCESS_PRIVATE_MEMBER: | ||
| CHECK_SYMBOLS(1); | ||
| return vformat(R"(Trying to access a private member "%s" from an external place, which would cause problems during runtime.)", symbols[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice, but it's not exactly mandatory, to specify what it is instead of "member", similar to what's done in #104955 .
No need to change anything in this PR, it's for future reference
1a584e8 to
39df719
Compare
|
I thought we were genuinely championing for this PR, it was just not the time to merge it right now? |
My brain was f**ked and forgot that this is something that would help users to avoid accessing private members. |
|
That's my personal opinion and was about hard access specifiers, not soft access specifiers like this |
|
Ok, since vnen agreed the implementation of this pr, I'm gonna squash it tonight to make this ready to merge. Maybe it will be in 4.5, or in 4.6. But no matter in which version, this pr can be finally done. |
|
Does this mean we will no longer get proper access modifiers? Using an underscore as a private variable means every time I want to change a var from private to public, or vice versa, I now break save game compatibility with my next update. The options now are to either wrap each saveable variable in a getter/setter (Which are extremely slow in GDScript) or check each variable when I save or load and adjust the saved/loaded name. These are both bad for a language specific to an environment where save game compatibility is extremely important as are save/load times. I have seen the arguments before 'But Python uses it', sure, but Python is not a language created specifically for game development. Using an access modifier causes me or anyone else none of these problems. |
39df719 to
548d828
Compare
__
We don't introduce the feature in a forced way (whether by adding
Yeah, I understand your point, but as I said this does not break compatibility as possible and you can configure it and turn it off. So you can keep the current codestyle you've been using.
How does Python has anything to do with this topic? I don't understand. :/ |
They mentioned it because it's a common argument in favor of this, they're not making the argument, they're referencing it |
|
Are there any plans to merge this in 4.6? |
Rebuilt on #98557
About the pr, see #98557
This time I removed
__naming convention, and left_only.