Skip to content

Commit e2d4469

Browse files
committed
GDScript: Add missing type conversions in for range
1 parent 51b0379 commit e2d4469

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

modules/gdscript/gdscript_byte_codegen.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,9 +1585,21 @@ void GDScriptByteCodeGenerator::write_for_range_assignment(const Address &p_from
15851585
const Address &range_step = for_range_step_variables.back()->get();
15861586

15871587
// Assign range args.
1588-
write_assign(range_from, p_from);
1589-
write_assign(range_to, p_to);
1590-
write_assign(range_step, p_step);
1588+
if (range_from.type == p_from.type) {
1589+
write_assign(range_from, p_from);
1590+
} else {
1591+
write_assign_with_conversion(range_from, p_from);
1592+
}
1593+
if (range_to.type == p_to.type) {
1594+
write_assign(range_to, p_to);
1595+
} else {
1596+
write_assign_with_conversion(range_to, p_to);
1597+
}
1598+
if (range_step.type == p_step.type) {
1599+
write_assign(range_step, p_step);
1600+
} else {
1601+
write_assign_with_conversion(range_step, p_step);
1602+
}
15911603
}
15921604

15931605
void GDScriptByteCodeGenerator::write_for(const Address &p_variable, bool p_use_conversion, bool p_is_range) {

modules/gdscript/gdscript_function.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,19 @@ class GDScriptDataType {
234234

235235
GDScriptDataType() = default;
236236

237+
bool operator==(const GDScriptDataType &p_other) const {
238+
return kind == p_other.kind &&
239+
has_type == p_other.has_type &&
240+
builtin_type == p_other.builtin_type &&
241+
native_type == p_other.native_type &&
242+
(script_type == p_other.script_type || script_type_ref == p_other.script_type_ref) &&
243+
container_element_types == p_other.container_element_types;
244+
}
245+
246+
bool operator!=(const GDScriptDataType &p_other) const {
247+
return !(*this == p_other);
248+
}
249+
237250
void operator=(const GDScriptDataType &p_other) {
238251
kind = p_other.kind;
239252
has_type = p_other.has_type;

modules/gdscript/tests/scripts/runtime/features/for_range_large_ints.gd renamed to modules/gdscript/tests/scripts/runtime/features/for_range.gd

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
# GH-83293
2-
31
func test():
2+
# GH-83293
43
for x in range(1 << 31, (1 << 31) + 3):
54
print(x)
65
for x in range(1 << 62, (1 << 62) + 3):
76
print(x)
7+
8+
# GH-107392
9+
var n = 1.0
10+
for x in range(n):
11+
print(x)

modules/gdscript/tests/scripts/runtime/features/for_range_large_ints.out renamed to modules/gdscript/tests/scripts/runtime/features/for_range.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ GDTEST_OK
55
4611686018427387904
66
4611686018427387905
77
4611686018427387906
8+
0

0 commit comments

Comments
 (0)