mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
GDScript: Fix typing of iterator in for loop
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
const constant_float = 1.0
|
||||
|
||||
func test():
|
||||
for x in constant_float:
|
||||
if x is String:
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
GDTEST_ANALYZER_ERROR
|
||||
Expression is of type "float" so it can't be of type "String".
|
||||
@@ -0,0 +1,6 @@
|
||||
const constant_int = 1
|
||||
|
||||
func test():
|
||||
for x in constant_int:
|
||||
if x is String:
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
GDTEST_ANALYZER_ERROR
|
||||
Expression is of type "int" so it can't be of type "String".
|
||||
@@ -0,0 +1,6 @@
|
||||
enum { enum_value = 1 }
|
||||
|
||||
func test():
|
||||
for x in enum_value:
|
||||
if x is String:
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
GDTEST_ANALYZER_ERROR
|
||||
Expression is of type "int" so it can't be of type "String".
|
||||
@@ -0,0 +1,6 @@
|
||||
func test():
|
||||
var hard_float := 1.0
|
||||
|
||||
for x in hard_float:
|
||||
if x is String:
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
GDTEST_ANALYZER_ERROR
|
||||
Expression is of type "float" so it can't be of type "String".
|
||||
@@ -0,0 +1,6 @@
|
||||
func test():
|
||||
var hard_int := 1
|
||||
|
||||
for x in hard_int:
|
||||
if x is String:
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
GDTEST_ANALYZER_ERROR
|
||||
Expression is of type "int" so it can't be of type "String".
|
||||
@@ -0,0 +1,14 @@
|
||||
class Iterator:
|
||||
func _iter_init(_count):
|
||||
return true
|
||||
func _iter_next(_count):
|
||||
return false
|
||||
func _iter_get(_count) -> StringName:
|
||||
return &'custom'
|
||||
|
||||
func test():
|
||||
var hard_iterator := Iterator.new()
|
||||
|
||||
for x in hard_iterator:
|
||||
if x is int:
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
GDTEST_ANALYZER_ERROR
|
||||
Expression is of type "StringName" so it can't be of type "int".
|
||||
@@ -0,0 +1,6 @@
|
||||
func test():
|
||||
var hard_string := 'a'
|
||||
|
||||
for x in hard_string:
|
||||
if x is int:
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
GDTEST_ANALYZER_ERROR
|
||||
Expression is of type "String" so it can't be of type "int".
|
||||
@@ -0,0 +1,3 @@
|
||||
func test():
|
||||
for x in true:
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
GDTEST_ANALYZER_ERROR
|
||||
Unable to iterate on value of type "bool".
|
||||
@@ -0,0 +1,4 @@
|
||||
func test():
|
||||
for x in 1:
|
||||
if x is String:
|
||||
pass
|
||||
@@ -0,0 +1,2 @@
|
||||
GDTEST_ANALYZER_ERROR
|
||||
Expression is of type "int" so it can't be of type "String".
|
||||
@@ -0,0 +1,15 @@
|
||||
func test():
|
||||
var variant_int: Variant = 1
|
||||
var weak_int = 1
|
||||
|
||||
for x in variant_int:
|
||||
if x is String:
|
||||
print('never')
|
||||
print(x)
|
||||
|
||||
for x in weak_int:
|
||||
if x is String:
|
||||
print('never')
|
||||
print(x)
|
||||
|
||||
print('ok')
|
||||
@@ -0,0 +1,4 @@
|
||||
GDTEST_OK
|
||||
0
|
||||
0
|
||||
ok
|
||||
@@ -0,0 +1,51 @@
|
||||
const constant_float = 1.0
|
||||
const constant_int = 1
|
||||
enum { enum_value = 1 }
|
||||
|
||||
class Iterator:
|
||||
func _iter_init(_count):
|
||||
return true
|
||||
func _iter_next(_count):
|
||||
return false
|
||||
func _iter_get(_count) -> StringName:
|
||||
return &'custom'
|
||||
|
||||
func test():
|
||||
var hard_float := 1.0
|
||||
var hard_int := 1
|
||||
var hard_string := '0'
|
||||
var hard_iterator := Iterator.new()
|
||||
|
||||
var variant_float: Variant = hard_float
|
||||
var variant_int: Variant = hard_int
|
||||
var variant_string: Variant = hard_string
|
||||
var variant_iterator: Variant = hard_iterator
|
||||
|
||||
for i in 1.0:
|
||||
print(typeof(i) == TYPE_FLOAT)
|
||||
for i in 1:
|
||||
print(typeof(i) == TYPE_INT)
|
||||
for i in 'a':
|
||||
print(typeof(i) == TYPE_STRING)
|
||||
for i in Iterator.new():
|
||||
print(typeof(i) == TYPE_STRING_NAME)
|
||||
|
||||
for i in hard_float:
|
||||
print(typeof(i) == TYPE_FLOAT)
|
||||
for i in hard_int:
|
||||
print(typeof(i) == TYPE_INT)
|
||||
for i in hard_string:
|
||||
print(typeof(i) == TYPE_STRING)
|
||||
for i in hard_iterator:
|
||||
print(typeof(i) == TYPE_STRING_NAME)
|
||||
|
||||
for i in variant_float:
|
||||
print(typeof(i) == TYPE_FLOAT)
|
||||
for i in variant_int:
|
||||
print(typeof(i) == TYPE_INT)
|
||||
for i in variant_string:
|
||||
print(typeof(i) == TYPE_STRING)
|
||||
for i in variant_iterator:
|
||||
print(typeof(i) == TYPE_STRING_NAME)
|
||||
|
||||
print('ok')
|
||||
@@ -0,0 +1,14 @@
|
||||
GDTEST_OK
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
true
|
||||
ok
|
||||
Reference in New Issue
Block a user