From 7e3b9f2d9edd6018c7a37dcb807c594dfd10d0d5 Mon Sep 17 00:00:00 2001
From: Lazy-Rabbit-2001 <2733679597@qq.com>
Date: Sat, 19 Oct 2024 22:48:39 +0800
Subject: [PATCH] fixed properties not protected, added the documentation for
@private and @protected
---
modules/gdscript/doc_classes/@GDScript.xml | 30 ++++++++++++++++++++++
modules/gdscript/gdscript_analyzer.cpp | 16 +++---------
2 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml
index 5fe47d69df6..d59f1dddf43 100644
--- a/modules/gdscript/doc_classes/@GDScript.xml
+++ b/modules/gdscript/doc_classes/@GDScript.xml
@@ -726,6 +726,36 @@
[/codeblock]
+
+
+
+ [i][b][color=orange]WARNING:[/color][/b] This annotation is an experimental feature and its behavior may casue issues and affect the performance on your device. Use this with caution.[/i]
+ Modifies the accessibility of the following member(constants, variables and functions) to [b]private[/b], which means that it can only be accessed from within the same script.
+ [codeblock]
+ # In Class A:
+ @private static var a = 10
+ # In Class B:
+ var b = A.a # Error: Cannot access private property 'a' from outside the class.
+ # In Class C that inherits from A:
+ var c = A.a # Error: Cannot access private property 'a' from outside the class.
+ [/codeblock]
+
+
+
+
+
+ [i][b][color=orange]WARNING:[/color][/b] This annotation is an experimental feature and its behavior may casue issues and affect the performance on your device. Use this with caution.[/i]
+ Modifies the accessibility of the following member(constants, variables and functions) to [b]protected[/b], which means that it can only be accessed from within the same script or a child of the same script.
+ [codeblock]
+ # In Class A:
+ @private static var a = 10
+ # In Class B:
+ var b = A.a # Error: Cannot access private property 'a' from outside the class.
+ # In Class C that inherits from A:
+ var c = A.a # OK: Can access protected property 'a' from the parent class.
+ [/codeblock]
+
+
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp
index 4dba72fee05..ba2b79c9230 100644
--- a/modules/gdscript/gdscript_analyzer.cpp
+++ b/modules/gdscript/gdscript_analyzer.cpp
@@ -4154,9 +4154,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod
p_identifier->reduced_value = member.constant->initializer->reduced_value;
p_identifier->source = GDScriptParser::IdentifierNode::MEMBER_CONSTANT;
p_identifier->constant_source = member.constant;
- if (member_source->identifier) {
- execute_access_protection(parser->current_class, member.get_name(), member_source->accessible_class_name, member_source->identifier->access_restriction, member_source->type, p_identifier);
- }
+ execute_access_protection(parser->current_class, member.get_name(), member_source->accessible_class_name, member_source->access_restriction, member_source->type, p_identifier);
return;
}
@@ -4182,9 +4180,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod
p_identifier->source = member.variable->is_static ? GDScriptParser::IdentifierNode::STATIC_VARIABLE : GDScriptParser::IdentifierNode::MEMBER_VARIABLE;
p_identifier->variable_source = member.variable;
member.variable->usages += 1;
- if (member_source->identifier) {
- execute_access_protection(parser->current_class, member.get_name(), member_source->accessible_class_name, member_source->identifier->access_restriction, member_source->type, p_identifier);
- }
+ execute_access_protection(parser->current_class, member.get_name(), member_source->accessible_class_name, member_source->access_restriction, member_source->type, p_identifier);
return;
}
} break;
@@ -4195,9 +4191,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod
p_identifier->source = GDScriptParser::IdentifierNode::MEMBER_SIGNAL;
p_identifier->signal_source = member.signal;
member.signal->usages += 1;
- if (member_source->identifier) {
- execute_access_protection(parser->current_class, member.get_name(), member_source->accessible_class_name, member_source->identifier->access_restriction, member_source->type, p_identifier);
- }
+ execute_access_protection(parser->current_class, member.get_name(), member_source->accessible_class_name, member_source->access_restriction, member_source->type, p_identifier);
return;
}
} break;
@@ -4208,9 +4202,7 @@ void GDScriptAnalyzer::reduce_identifier_from_base(GDScriptParser::IdentifierNod
p_identifier->source = GDScriptParser::IdentifierNode::MEMBER_FUNCTION;
p_identifier->function_source = member.function;
p_identifier->function_source_is_static = member.function->is_static;
- if (member_source->identifier) {
- execute_access_protection(parser->current_class, member.get_name(), member_source->accessible_class_name, member_source->identifier->access_restriction, member_source->type, p_identifier);
- }
+ execute_access_protection(parser->current_class, member.get_name(), member_source->accessible_class_name, member_source->access_restriction, member_source->type, p_identifier);
return;
}
} break;