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

Add clearer error messages when using set/get incorrectly. #91506

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions modules/gdscript/gdscript_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,8 +1095,34 @@ GDScriptParser::VariableNode *GDScriptParser::parse_variable(bool p_is_static, b
}

complete_extents(variable);

bool malformed_setget_found = false;

if (p_allow_property && check(GDScriptTokenizer::Token::IDENTIFIER)) {
StringName identifier_name = current.get_identifier();
if (identifier_name == SNAME("set") || identifier_name == SNAME("get")) {
push_error(vformat(R"(Expected ":" before "%s".)", identifier_name));
malformed_setget_found = true;
}
}

end_statement("variable declaration");

if (p_allow_property && !malformed_setget_found && match(GDScriptTokenizer::Token::INDENT)) {
if (check(GDScriptTokenizer::Token::IDENTIFIER)) {
StringName identifier_name = current.get_identifier();
if (identifier_name == SNAME("set") || identifier_name == SNAME("get")) {
malformed_setget_found = true;
}
}

if (malformed_setget_found) {
push_error(vformat(R"(Expected ":" at end of variable declaration when using "set" or "get")"), variable);
} else {
push_error(R"(Unexpected "Indent" after variable declaration.)");
}
}

return variable;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#GDTEST_PARSER_ERROR

var property
get():
return 0

func test():
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected ":" at end of variable declaration when using "set" or "get"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#GDTEST_PARSER_ERROR

var property get = get_property

func test():
pass

func get_property():
return 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected ":" before "get".