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

Improve misleading Unexpected "x" in class body. GDScript parser error #99887

Merged
merged 1 commit into from
Dec 10, 2024
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
2 changes: 1 addition & 1 deletion modules/gdscript/gdscript_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,8 +1060,8 @@ void GDScriptParser::parse_class_body(bool p_is_multiline) {
default:
// Display a completion with identifiers.
make_completion_context(COMPLETION_IDENTIFIER, nullptr);
push_error(vformat(R"(Unexpected "%s" in class body.)", current.get_name()));
advance();
push_error(vformat(R"(Unexpected %s in class body.)", previous.get_debug_name()));
break;
}
if (token.type != GDScriptTokenizer::Token::STATIC) {
Expand Down
9 changes: 9 additions & 0 deletions modules/gdscript/gdscript_tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ const char *GDScriptTokenizer::Token::get_name() const {
return token_names[type];
}

String GDScriptTokenizer::Token::get_debug_name() const {
switch (type) {
case IDENTIFIER:
return vformat(R"(identifier "%s")", source);
default:
return vformat(R"("%s")", get_name());
}
}

bool GDScriptTokenizer::Token::can_precede_bin_op() const {
switch (type) {
case IDENTIFIER:
Expand Down
1 change: 1 addition & 0 deletions modules/gdscript/gdscript_tokenizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class GDScriptTokenizer {
String source;

const char *get_name() const;
String get_debug_name() const;
bool can_precede_bin_op() const;
bool is_identifier() const;
bool is_node_name() const;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# GH-96792

var error
error = true

func test():
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Unexpected identifier "error" in class body.