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

GDScript: Allow empty parentheses for property getter declaration #83120

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions modules/gdscript/gdscript_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,12 @@ void GDScriptParser::parse_property_getter(VariableNode *p_variable) {
case VariableNode::PROP_INLINE: {
FunctionNode *function = alloc_node<FunctionNode>();

consume(GDScriptTokenizer::Token::COLON, R"(Expected ":" after "get".)");
if (match(GDScriptTokenizer::Token::PARENTHESIS_OPEN)) {
consume(GDScriptTokenizer::Token::PARENTHESIS_CLOSE, R"*(Expected ")" after "get(".)*");
consume(GDScriptTokenizer::Token::COLON, R"*(Expected ":" after "get()".)*");
} else {
consume(GDScriptTokenizer::Token::COLON, R"(Expected ":" or "(" after "get".)");
}

IdentifierNode *identifier = alloc_node<IdentifierNode>();
complete_extents(identifier);
Expand Down Expand Up @@ -1264,8 +1269,7 @@ GDScriptParser::EnumNode *GDScriptParser::parse_enum(bool p_is_static) {
EnumNode *enum_node = alloc_node<EnumNode>();
bool named = false;

if (check(GDScriptTokenizer::Token::IDENTIFIER)) {
advance();
if (match(GDScriptTokenizer::Token::IDENTIFIER)) {
enum_node->identifier = parse_identifier();
named = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ var property:
set(value):
_backing = value - 1000

var property_2:
get(): # Allow parentheses.
return 123

func test():
print("Not using self:")
Expand Down Expand Up @@ -35,3 +38,5 @@ func test():
self.property = 5000
print(self.property)
print(self._backing)

print(property_2)
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Using self:
-50
5000
4000
123
Loading