-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GDScript: Add static typing for
for
loop variable
- Loading branch information
Showing
20 changed files
with
177 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
modules/gdscript/tests/scripts/analyzer/errors/for_loop_wrong_specified_type.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
func test(): | ||
var a: Array[Resource] = [] | ||
for node: Node in a: | ||
print(node) |
2 changes: 2 additions & 0 deletions
2
modules/gdscript/tests/scripts/analyzer/errors/for_loop_wrong_specified_type.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GDTEST_ANALYZER_ERROR | ||
Unable to iterate on value of type "Array[Resource]" with variable of type "Node". |
4 changes: 4 additions & 0 deletions
4
.../gdscript/tests/scripts/analyzer/warnings/for_loop_specified_type_is_equal_to_inferred.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
func test(): | ||
var a: Array[Node] = [] | ||
for node: Node in a: | ||
print(node) |
5 changes: 5 additions & 0 deletions
5
...gdscript/tests/scripts/analyzer/warnings/for_loop_specified_type_is_equal_to_inferred.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
GDTEST_OK | ||
>> WARNING | ||
>> Line: 3 | ||
>> REDUNDANT_FOR_VARIABLE_TYPE | ||
>> The for loop iterator "node" already has inferred type "Node", the specified type is redundant. |
4 changes: 4 additions & 0 deletions
4
...cript/tests/scripts/analyzer/warnings/for_loop_specified_type_is_supertype_of_inferred.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
func test(): | ||
var a: Array[Node2D] = [] | ||
for node: Node in a: | ||
print(node) |
5 changes: 5 additions & 0 deletions
5
...ript/tests/scripts/analyzer/warnings/for_loop_specified_type_is_supertype_of_inferred.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
GDTEST_OK | ||
>> WARNING | ||
>> Line: 3 | ||
>> REDUNDANT_FOR_VARIABLE_TYPE | ||
>> The for loop iterator "node" has inferred type "Node2D" but its supertype "Node" is specified. |
4 changes: 4 additions & 0 deletions
4
modules/gdscript/tests/scripts/runtime/errors/for_loop_iterator_type_not_match_specified.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
func test(): | ||
var a: Array = [Resource.new()] | ||
for node: Node in a: | ||
print(node) |
6 changes: 6 additions & 0 deletions
6
modules/gdscript/tests/scripts/runtime/errors/for_loop_iterator_type_not_match_specified.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
GDTEST_RUNTIME_ERROR | ||
>> SCRIPT ERROR | ||
>> on function: test() | ||
>> runtime/errors/for_loop_iterator_type_not_match_specified.gd | ||
>> 3 | ||
>> Trying to assign value of type 'Resource' to a variable of type 'Node'. |
34 changes: 34 additions & 0 deletions
34
modules/gdscript/tests/scripts/runtime/features/for_loop_iterator_specified_types.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
func test(): | ||
print("Test range.") | ||
for e: float in range(2, 5): | ||
var elem := e | ||
prints(var_to_str(e), var_to_str(elem)) | ||
|
||
print("Test int.") | ||
for e: float in 3: | ||
var elem := e | ||
prints(var_to_str(e), var_to_str(elem)) | ||
|
||
print("Test untyped int array.") | ||
var a1 := [10, 20, 30] | ||
for e: float in a1: | ||
var elem := e | ||
prints(var_to_str(e), var_to_str(elem)) | ||
|
||
print("Test typed int array.") | ||
var a2: Array[int] = [10, 20, 30] | ||
for e: float in a2: | ||
var elem := e | ||
prints(var_to_str(e), var_to_str(elem)) | ||
|
||
print("Test String-keys dictionary.") | ||
var d1 := {a = 1, b = 2, c = 3} | ||
for k: StringName in d1: | ||
var key := k | ||
prints(var_to_str(k), var_to_str(key)) | ||
|
||
print("Test RefCounted-keys dictionary.") | ||
var d2 := {RefCounted.new(): 1, Resource.new(): 2, ConfigFile.new(): 3} | ||
for k: RefCounted in d2: | ||
var key := k | ||
prints(k.get_class(), key.get_class()) |
25 changes: 25 additions & 0 deletions
25
modules/gdscript/tests/scripts/runtime/features/for_loop_iterator_specified_types.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
GDTEST_OK | ||
Test range. | ||
2.0 2.0 | ||
3.0 3.0 | ||
4.0 4.0 | ||
Test int. | ||
0.0 0.0 | ||
1.0 1.0 | ||
2.0 2.0 | ||
Test untyped int array. | ||
10.0 10.0 | ||
20.0 20.0 | ||
30.0 30.0 | ||
Test typed int array. | ||
10.0 10.0 | ||
20.0 20.0 | ||
30.0 30.0 | ||
Test String-keys dictionary. | ||
&"a" &"a" | ||
&"b" &"b" | ||
&"c" &"c" | ||
Test RefCounted-keys dictionary. | ||
RefCounted RefCounted | ||
Resource Resource | ||
ConfigFile ConfigFile |