Reimplement soft access restriction for members prefixed with _#103768
Reimplement soft access restriction for members prefixed with _#103768Lazy-Rabbit-2001 wants to merge 1 commit intogodotengine:masterfrom
_#103768Conversation
|
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
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 |
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? |
I've asked many times in the rocket chat but nobody has given this a look yet... sad |
|
Could you double check whether you included unrelated changes? The diff contains some create dialog changes in editor interface, for which it's not directly obvious to me how they relate to this PR. |
This wasn't really the point I was trying to make. I do want a way to mark my variables as private or public, so I will use whatever is ultimately implemented. But imo having proper access modifiers is the correct way to go, for reasons previously mentioned. So if this is going to hinder or even halt that feature being merged in the future, then that is not good. Hence my question. It also helps me decide if I should use this feature at all if it ends up being merged, as I don't want to break all saves in the future when needing to change. For some of us working on large projects, whom plan to release into Early access, its helpful to give us an idea of what's planned or likely to change/happen regarding certain features, so we can then make informed decisions within our own codebase. |
548d828 to
09a45d3
Compare
The feature won't eliminate the solution to introduce either a keyword
This is implemented by warnings, so you can disable them in your project settings or enable them as you wish. The warnings will not break your current project as long as you do not switch the warnings to errors. |
|
@produno Can you explain which feature you're using that changing variable names breaks compatibility? I assume you're passing some of your objects directly into one of the serialization functions, without specifying key names explicitly?
While there was a consensus in a previous GDScript meeting that this PR was desirable, it is still up for debate. If we find it is not mergeable due to other concerns, it will not be merged. |
I save the property name with its value, then upon load I use |
|
Currently there is either using
|
09a45d3 to
9105398
Compare
|
pushed an update thatt is unrelated to this pr (exactly saying, it's about the create_dialog.cpp, but I'd no idea why the update conflicted with this one...) |
modules/gdscript/tests/scripts/analyzer/features/warning_ignore_warnings.out
Outdated
Show resolved
Hide resolved
modules/gdscript/tests/scripts/analyzer/features/warning_ignore_warnings.gd
Outdated
Show resolved
Hide resolved
modules/gdscript/tests/scripts/analyzer/warnings/access_modifier_soft.gd
Outdated
Show resolved
Hide resolved
9105398 to
35ffe16
Compare
4ff4afd to
10241a1
Compare
10241a1 to
797b70a
Compare
797b70a to
14276d0
Compare
Rebuilt on #98557
Info
About the pr, see #98557
This time I removed
__naming convention, and left_only.The question about whether this will block further migration to using
privateor@privateNo, as this pr implements the system driven by the warnings and it will be very easy to migrate the grammar to using prefixes as long as it is still warning-driven.
However, I'm afraid we would not resort to the former as members have agreed with using annotations over keywords for modifying grammars (except
static). to keep compatibility and, more important, performance.Progress