Merge pull request #68125 from kleonc/range-fix-single-arg-optimized-type-mismatch

[GDScript] Fix type mismatch in optimized single arg `range`
This commit is contained in:
Rémi Verschelde 2022-11-02 14:18:24 +01:00
commit 7eb44fa47d
No known key found for this signature in database
GPG key ID: C3336907360768E1
5 changed files with 140 additions and 1 deletions

View file

@ -1382,7 +1382,7 @@ void GDScriptAnalyzer::resolve_for(GDScriptParser::ForNode *p_for) {
if (all_is_constant) { if (all_is_constant) {
switch (args.size()) { switch (args.size()) {
case 1: case 1:
reduced = args[0]; reduced = (int32_t)args[0];
break; break;
case 2: case 2:
reduced = Vector2i(args[0], args[1]); reduced = Vector2i(args[0], args[1]);

View file

@ -0,0 +1,60 @@
func test():
# All combinations of 1/2/3 arguments, each being int/float.
for number in range(5):
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
for number in range(5.2):
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
for number in range(1, 5):
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
for number in range(1, 5.2):
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
for number in range(1.2, 5):
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
for number in range(1.2, 5.2):
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
for number in range(1, 5, 2):
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
for number in range(1, 5, 2.2):
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
for number in range(1, 5.2, 2):
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
for number in range(1, 5.2, 2.2):
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
for number in range(1.2, 5, 2):
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
for number in range(1.2, 5.2, 2):
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
for number in range(1.2, 5, 2.2):
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
for number in range(1.2, 5.2, 2.2):
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")

View file

@ -0,0 +1,77 @@
func test():
# All combinations of 1/2/3 arguments, each being int/float.
# Store result in variable to ensure actual array is created (avoid `for` + `range` optimization).
var result
result = range(5)
for number in result:
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
result = range(5.2)
for number in result:
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
result = range(1, 5)
for number in result:
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
result = range(1, 5.2)
for number in result:
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
result = range(1.2, 5)
for number in result:
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
result = range(1.2, 5.2)
for number in result:
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
result = range(1, 5, 2)
for number in result:
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
result = range(1, 5, 2.2)
for number in result:
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
result = range(1, 5.2, 2)
for number in result:
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
result = range(1, 5.2, 2.2)
for number in result:
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
result = range(1.2, 5, 2)
for number in result:
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
result = range(1.2, 5.2, 2)
for number in result:
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
result = range(1.2, 5, 2.2)
for number in result:
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")
result = range(1.2, 5.2, 2.2)
for number in result:
if typeof(number) != TYPE_INT:
print("Number returned from `range` was not an int!")

View file

@ -0,0 +1 @@
GDTEST_OK