Browse Source

Add errors for keywords removed in Godot 4

Update modules/gdscript/gdscript_parser.cpp

Co-authored-by: Danil Alexeev <[email protected]>

Improve error message

Add tests

Add errors for other removed keywords

Remove very old keywords and improve wording of errors
Malcolm Anderson 5 months ago
parent
commit
5c662f7707

+ 21 - 1
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) {

+ 5 - 0
modules/gdscript/tests/scripts/parser/errors/export_godot3_syntax.gd

@@ -0,0 +1,5 @@
+export var test = 3
+
+
+func test():
+	pass

+ 2 - 0
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.

+ 5 - 0
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

+ 2 - 0
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.