Merge pull request #107416 from dalexeev/gds-fix-for-range-assignment

GDScript: Add missing type conversions in `for range`
This commit is contained in:
Rémi Verschelde 2025-06-12 22:49:08 +02:00
commit ea908f1ab2
No known key found for this signature in database
GPG Key ID: C3336907360768E1
4 changed files with 35 additions and 5 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -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)

View File

@ -5,3 +5,4 @@ GDTEST_OK
4611686018427387904
4611686018427387905
4611686018427387906
0