From 5c662f7707e82f2b4d5d62d5cf296d2709b3628a Mon Sep 17 00:00:00 2001 From: Malcolm Anderson Date: Tue, 25 Mar 2025 21:12:52 -0700 Subject: [PATCH] Add errors for keywords removed in Godot 4 Update modules/gdscript/gdscript_parser.cpp Co-authored-by: Danil Alexeev Improve error message Add tests Add errors for other removed keywords Remove very old keywords and improve wording of errors --- modules/gdscript/gdscript_parser.cpp | 22 ++++++++++++++++++- .../parser/errors/export_godot3_syntax.gd | 5 +++++ .../parser/errors/export_godot3_syntax.out | 2 ++ .../errors/export_godot3_syntax_with_args.gd | 5 +++++ .../errors/export_godot3_syntax_with_args.out | 2 ++ 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 modules/gdscript/tests/scripts/parser/errors/export_godot3_syntax.gd create mode 100644 modules/gdscript/tests/scripts/parser/errors/export_godot3_syntax.out create mode 100644 modules/gdscript/tests/scripts/parser/errors/export_godot3_syntax_with_args.gd create mode 100644 modules/gdscript/tests/scripts/parser/errors/export_godot3_syntax_with_args.out diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index b6231d06b2b..698675677af 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -1087,7 +1087,27 @@ void GDScriptParser::parse_class_body(bool p_is_multiline) { // Display a completion with identifiers. make_completion_context(COMPLETION_IDENTIFIER, nullptr); advance(); - push_error(vformat(R"(Unexpected %s in class body.)", previous.get_debug_name())); + if (previous.get_identifier() == "export") { + push_error(R"(The "export" keyword was removed in Godot 4. Use an export annotation ("@export", "@export_range", etc.) instead.)"); + } else if (previous.get_identifier() == "tool") { + push_error(R"(The "tool" keyword was removed in Godot 4. Use the "@tool" annotation instead.)"); + } else if (previous.get_identifier() == "onready") { + push_error(R"(The "onready" keyword was removed in Godot 4. Use the "@onready" annotation instead.)"); + } else if (previous.get_identifier() == "remote") { + push_error(R"(The "remote" keyword was removed in Godot 4. Use the "@rpc" annotation with "any_peer" instead.)"); + } else if (previous.get_identifier() == "remotesync") { + push_error(R"(The "remotesync" keyword was removed in Godot 4. Use the "@rpc" annotation with "any_peer" and "call_local" instead.)"); + } else if (previous.get_identifier() == "puppet") { + push_error(R"(The "puppet" keyword was removed in Godot 4. Use the "@rpc" annotation with "authority" instead.)"); + } else if (previous.get_identifier() == "puppetsync") { + push_error(R"(The "puppetsync" keyword was removed in Godot 4. Use the "@rpc" annotation with "authority" and "call_local" instead.)"); + } else if (previous.get_identifier() == "master") { + push_error(R"(The "master" keyword was removed in Godot 4. Use the "@rpc" annotation with "any_peer" and perform a check inside the function instead.)"); + } else if (previous.get_identifier() == "mastersync") { + push_error(R"(The "mastersync" keyword was removed in Godot 4. Use the "@rpc" annotation with "any_peer" and "call_local", and perform a check inside the function instead.)"); + } else { + push_error(vformat(R"(Unexpected %s in class body.)", previous.get_debug_name())); + } break; } if (token.type != GDScriptTokenizer::Token::STATIC) { diff --git a/modules/gdscript/tests/scripts/parser/errors/export_godot3_syntax.gd b/modules/gdscript/tests/scripts/parser/errors/export_godot3_syntax.gd new file mode 100644 index 00000000000..e73c264a7aa --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/export_godot3_syntax.gd @@ -0,0 +1,5 @@ +export var test = 3 + + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/parser/errors/export_godot3_syntax.out b/modules/gdscript/tests/scripts/parser/errors/export_godot3_syntax.out new file mode 100644 index 00000000000..71c82f5c132 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/export_godot3_syntax.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +The "export" keyword was removed in Godot 4. Use an export annotation ("@export", "@export_range", etc.) instead. diff --git a/modules/gdscript/tests/scripts/parser/errors/export_godot3_syntax_with_args.gd b/modules/gdscript/tests/scripts/parser/errors/export_godot3_syntax_with_args.gd new file mode 100644 index 00000000000..2320653b1f3 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/export_godot3_syntax_with_args.gd @@ -0,0 +1,5 @@ +export(int, "a", "b", "c") var test = 3 + + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/parser/errors/export_godot3_syntax_with_args.out b/modules/gdscript/tests/scripts/parser/errors/export_godot3_syntax_with_args.out new file mode 100644 index 00000000000..71c82f5c132 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/errors/export_godot3_syntax_with_args.out @@ -0,0 +1,2 @@ +GDTEST_PARSER_ERROR +The "export" keyword was removed in Godot 4. Use an export annotation ("@export", "@export_range", etc.) instead.