summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorRyan Roden-Corrent <ryan@rcorre.net>2023-03-03 18:31:40 -0500
committerYuri Sizov <yuris@humnom.net>2023-03-13 21:19:53 +0100
commit6cd227a35c3ca27d138e99582dcf8b1e4ac20aa6 (patch)
tree982f5e50b6600a487537d88cd492aa0666275729 /editor
parent1421838ba79bd14a978831672b28efe0b5fff866 (diff)
Correct superclass constructors in 3to4.
Fixes #70542. The 3to4 conversion tool was not handling superclass constructors. We should translate the godot3 syntax: ```gdscript func _init(a,b,c).(a,b,c): pass func _init(a,b,c): super(a,b,c) ``` Originally, the _init conversion was intended to remove `void` return types from _init functions, as this was disallowed due to #50589. As that was resolved by #53366, I removed that part of the conversion logic. If a void return type is present on a constructor, the converter now leaves it. Here's a sample diff from my own project: ```diff @@ -103,10 +105,11 @@ class Real: class Text: extends Setting - var choices: PoolStringArray - var value: String setget set_value, get_value + var choices: PackedStringArray + var value: String : get = get_value, set = set_value - func _init(section: String, key: String, default: String, choice_list: Array).(section, key, default) -> void: + func _init(section: String, key: String, default: String, choice_list: Array) -> void: + super(section, key, default) choices = choice_list func normalize(val): @@ -129,9 +132,10 @@ class Text: class Boolean: extends Setting - var value: bool setget set_value, get_value + var value: bool : get = get_value, set = set_value - func _init(section: String, key: String, default: bool).(section, key, default) -> void: + func _init(section: String, key: String, default: bool) -> void: + super(section, key, default) pass ``` (cherry picked from commit 53a00abb11cbbdceba7f7d027e7455854bfef01e)
Diffstat (limited to 'editor')
-rw-r--r--editor/project_converter_3_to_4.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/editor/project_converter_3_to_4.cpp b/editor/project_converter_3_to_4.cpp
index 285351f107..5ff438db8f 100644
--- a/editor/project_converter_3_to_4.cpp
+++ b/editor/project_converter_3_to_4.cpp
@@ -884,7 +884,10 @@ bool ProjectConverter3To4::test_conversion(RegExContainer &reg_container) {
valid = valid && test_conversion_gdscript_builtin("(tween_callback(A,B,[C,D]).foo())", "(tween_callback(Callable(A, B).bind(C,D)).foo())", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
valid = valid && test_conversion_gdscript_builtin("func _init(", "func _init(", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
- valid = valid && test_conversion_gdscript_builtin("func _init(p_x:int)->void:", "func _init(p_x:int):", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
+ valid = valid && test_conversion_gdscript_builtin("func _init(a,b,c).(d,e,f):", "func _init(a,b,c):\n\tsuper(d,e,f)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
+ valid = valid && test_conversion_gdscript_builtin("func _init(a,b,c).(a.b(),c.d()):", "func _init(a,b,c):\n\tsuper(a.b(),c.d())", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
+ valid = valid && test_conversion_gdscript_builtin("func _init(p_x:int)->void:", "func _init(p_x:int)->void:", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
+ valid = valid && test_conversion_gdscript_builtin("func _init(a: int).(d,e,f) -> void:", "func _init(a: int) -> void:\n\tsuper(d,e,f)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
valid = valid && test_conversion_gdscript_builtin("q_PackedDataContainer._iter_init(variable1)", "q_PackedDataContainer._iter_init(variable1)", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
valid = valid && test_conversion_gdscript_builtin("assert(speed < 20, str(randi()%10))", "assert(speed < 20) #,str(randi()%10))", &ProjectConverter3To4::rename_gdscript_functions, "custom rename", reg_container, false);
@@ -1934,17 +1937,18 @@ void ProjectConverter3To4::process_gdscript_line(String &line, const RegExContai
}
}
}
- // -- func _init(p_x:int)->void: -> func _init(p_x:int): Object # https://github.com/godotengine/godot/issues/50589
- if (line.contains(" _init(")) {
- int start = line.find(" _init(");
- if (line.contains(":")) {
- int end = line.rfind(":") + 1;
- if (end > -1) {
- Vector<String> parts = parse_arguments(line.substr(start, end));
- line = line.substr(0, start) + " _init(" + connect_arguments(parts, 0) + "):" + line.substr(end + start);
- }
+ // -- func _init(p_x:int).(p_x): -> func _init(p_x:int):\n\tsuper(p_x) Object # https://github.com/godotengine/godot/issues/70542
+ if (line.contains(" _init(") && line.rfind(":") > 0) {
+ // func _init(p_arg1).(super4, super5, super6)->void:
+ // ^--^indent ^super_start super_end^
+ int indent = line.count("\t", 0, line.find("func"));
+ int super_start = line.find(".(");
+ int super_end = line.rfind(")");
+ if (super_start > 0 && super_end > super_start) {
+ line = line.substr(0, super_start) + line.substr(super_end + 1) + "\n" + String("\t").repeat(indent + 1) + "super" + line.substr(super_start + 1, super_end - super_start);
}
}
+
// assert(speed < 20, str(randi()%10)) -> assert(speed < 20) #,str(randi()%10)) GDScript - GDScript bug constant message
if (line.contains("assert(")) {
int start = line.find("assert(");