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:
commit
7eb44fa47d
5 changed files with 140 additions and 1 deletions
|
@ -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]);
|
||||||
|
|
|
@ -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!")
|
|
@ -0,0 +1 @@
|
||||||
|
GDTEST_OK
|
|
@ -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!")
|
|
@ -0,0 +1 @@
|
||||||
|
GDTEST_OK
|
Loading…
Reference in a new issue