From e2d4469dc247a1b40aba72bf70fb9d2b30e0b134 Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Wed, 11 Jun 2025 20:45:47 +0300 Subject: [PATCH] GDScript: Add missing type conversions in `for range` --- modules/gdscript/gdscript_byte_codegen.cpp | 18 +++++++++++++++--- modules/gdscript/gdscript_function.h | 13 +++++++++++++ .../{for_range_large_ints.gd => for_range.gd} | 8 ++++++-- ...{for_range_large_ints.out => for_range.out} | 1 + 4 files changed, 35 insertions(+), 5 deletions(-) rename modules/gdscript/tests/scripts/runtime/features/{for_range_large_ints.gd => for_range.gd} (63%) rename modules/gdscript/tests/scripts/runtime/features/{for_range_large_ints.out => for_range.out} (98%) diff --git a/modules/gdscript/gdscript_byte_codegen.cpp b/modules/gdscript/gdscript_byte_codegen.cpp index 486ffbe40a0..16ac4d418e0 100644 --- a/modules/gdscript/gdscript_byte_codegen.cpp +++ b/modules/gdscript/gdscript_byte_codegen.cpp @@ -1585,9 +1585,21 @@ void GDScriptByteCodeGenerator::write_for_range_assignment(const Address &p_from const Address &range_step = for_range_step_variables.back()->get(); // Assign range args. - write_assign(range_from, p_from); - write_assign(range_to, p_to); - write_assign(range_step, p_step); + if (range_from.type == p_from.type) { + write_assign(range_from, p_from); + } else { + write_assign_with_conversion(range_from, p_from); + } + if (range_to.type == p_to.type) { + write_assign(range_to, p_to); + } else { + write_assign_with_conversion(range_to, p_to); + } + if (range_step.type == p_step.type) { + write_assign(range_step, p_step); + } else { + write_assign_with_conversion(range_step, p_step); + } } void GDScriptByteCodeGenerator::write_for(const Address &p_variable, bool p_use_conversion, bool p_is_range) { diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h index e03e4a6b978..438249d579c 100644 --- a/modules/gdscript/gdscript_function.h +++ b/modules/gdscript/gdscript_function.h @@ -234,6 +234,19 @@ public: GDScriptDataType() = default; + bool operator==(const GDScriptDataType &p_other) const { + return kind == p_other.kind && + has_type == p_other.has_type && + builtin_type == p_other.builtin_type && + native_type == p_other.native_type && + (script_type == p_other.script_type || script_type_ref == p_other.script_type_ref) && + container_element_types == p_other.container_element_types; + } + + bool operator!=(const GDScriptDataType &p_other) const { + return !(*this == p_other); + } + void operator=(const GDScriptDataType &p_other) { kind = p_other.kind; has_type = p_other.has_type; diff --git a/modules/gdscript/tests/scripts/runtime/features/for_range_large_ints.gd b/modules/gdscript/tests/scripts/runtime/features/for_range.gd similarity index 63% rename from modules/gdscript/tests/scripts/runtime/features/for_range_large_ints.gd rename to modules/gdscript/tests/scripts/runtime/features/for_range.gd index 36a1525cc6a..fc95c34a3c1 100644 --- a/modules/gdscript/tests/scripts/runtime/features/for_range_large_ints.gd +++ b/modules/gdscript/tests/scripts/runtime/features/for_range.gd @@ -1,7 +1,11 @@ -# GH-83293 - func test(): + # GH-83293 for x in range(1 << 31, (1 << 31) + 3): print(x) for x in range(1 << 62, (1 << 62) + 3): print(x) + + # GH-107392 + var n = 1.0 + for x in range(n): + print(x) diff --git a/modules/gdscript/tests/scripts/runtime/features/for_range_large_ints.out b/modules/gdscript/tests/scripts/runtime/features/for_range.out similarity index 98% rename from modules/gdscript/tests/scripts/runtime/features/for_range_large_ints.out rename to modules/gdscript/tests/scripts/runtime/features/for_range.out index 08932d9bab7..55abbe56064 100644 --- a/modules/gdscript/tests/scripts/runtime/features/for_range_large_ints.out +++ b/modules/gdscript/tests/scripts/runtime/features/for_range.out @@ -5,3 +5,4 @@ GDTEST_OK 4611686018427387904 4611686018427387905 4611686018427387906 +0