Skip to content

Commit

Permalink
Merge pull request #83120 from dalexeev/gds-allow-property-getter-emp…
Browse files Browse the repository at this point in the history
…ty-parentheses

GDScript: Allow empty parentheses for property getter declaration
  • Loading branch information
akien-mga committed Jan 4, 2024
2 parents 0010096 + 668ba2d commit 150f2a7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
10 changes: 7 additions & 3 deletions modules/gdscript/gdscript_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,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 @@ -1268,8 +1273,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

0 comments on commit 150f2a7

Please sign in to comment.