Skip to content

Commit

Permalink
fixed properties not protected, added the documentation for @Private
Browse files Browse the repository at this point in the history
…and @Protected
  • Loading branch information
Lazy-Rabbit-2001 committed Oct 19, 2024
1 parent 96bfd8a commit 7e3b9f2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
30 changes: 30 additions & 0 deletions modules/gdscript/doc_classes/@GDScript.xml
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,36 @@
[/codeblock]
</description>
</annotation>
<annotation name="@private">
<return type="void" />
<description>
[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]
</description>
</annotation>
<annotation name="@protected", experimental="This is still an experimental feature with unstability and potential performace issues. Be careful when using it in your code.">
<return type="void" />
<description>
[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]
</description>
</annotation>
<annotation name="@rpc">
<return type="void" />
<param index="0" name="mode" type="String" default="&quot;authority&quot;" />
Expand Down
16 changes: 4 additions & 12 deletions modules/gdscript/gdscript_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 7e3b9f2

Please sign in to comment.