forked from godotengine/godot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
150 additions
and
6 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
3 changes: 3 additions & 0 deletions
3
modules/gdscript/tests/scripts/analyzer/errors/cast_int_to_array.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,3 @@ | ||
func test(): | ||
var integer := 1 | ||
print(integer as Array) |
2 changes: 2 additions & 0 deletions
2
modules/gdscript/tests/scripts/analyzer/errors/cast_int_to_array.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 | ||
Invalid cast. Cannot convert from "int" to "Array". |
3 changes: 3 additions & 0 deletions
3
modules/gdscript/tests/scripts/analyzer/errors/cast_int_to_object.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,3 @@ | ||
func test(): | ||
var integer := 1 | ||
print(integer as Node) |
2 changes: 2 additions & 0 deletions
2
modules/gdscript/tests/scripts/analyzer/errors/cast_int_to_object.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 | ||
Invalid cast. Cannot convert from "int" to "Node". |
3 changes: 3 additions & 0 deletions
3
modules/gdscript/tests/scripts/analyzer/errors/cast_object_to_int.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,3 @@ | ||
func test(): | ||
var object := RefCounted.new() | ||
print(object as int) |
2 changes: 2 additions & 0 deletions
2
modules/gdscript/tests/scripts/analyzer/errors/cast_object_to_int.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 | ||
Invalid cast. Cannot convert from "RefCounted" to "int". |
24 changes: 24 additions & 0 deletions
24
modules/gdscript/tests/scripts/analyzer/warnings/unsafe_cast.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,24 @@ | ||
# We don't want to execute it because of errors, just analyze. | ||
func no_exec_test(): | ||
var weak_int = 1 | ||
print(weak_int as Variant) # No warning. | ||
print(weak_int as int) | ||
print(weak_int as Node) | ||
|
||
var weak_node = Node.new() | ||
print(weak_node as Variant) # No warning. | ||
print(weak_node as int) | ||
print(weak_node as Node) | ||
|
||
var weak_variant = null | ||
print(weak_variant as Variant) # No warning. | ||
print(weak_variant as int) | ||
print(weak_variant as Node) | ||
|
||
var hard_variant: Variant = null | ||
print(hard_variant as Variant) # No warning. | ||
print(hard_variant as int) | ||
print(hard_variant as Node) | ||
|
||
func test(): | ||
pass |
33 changes: 33 additions & 0 deletions
33
modules/gdscript/tests/scripts/analyzer/warnings/unsafe_cast.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,33 @@ | ||
GDTEST_OK | ||
>> WARNING | ||
>> Line: 5 | ||
>> UNSAFE_CAST | ||
>> Casting "Variant" to "int" is unsafe. | ||
>> WARNING | ||
>> Line: 6 | ||
>> UNSAFE_CAST | ||
>> Casting "Variant" to "Node" is unsafe. | ||
>> WARNING | ||
>> Line: 10 | ||
>> UNSAFE_CAST | ||
>> Casting "Variant" to "int" is unsafe. | ||
>> WARNING | ||
>> Line: 11 | ||
>> UNSAFE_CAST | ||
>> Casting "Variant" to "Node" is unsafe. | ||
>> WARNING | ||
>> Line: 15 | ||
>> UNSAFE_CAST | ||
>> Casting "Variant" to "int" is unsafe. | ||
>> WARNING | ||
>> Line: 16 | ||
>> UNSAFE_CAST | ||
>> Casting "Variant" to "Node" is unsafe. | ||
>> WARNING | ||
>> Line: 20 | ||
>> UNSAFE_CAST | ||
>> Casting "Variant" to "int" is unsafe. | ||
>> WARNING | ||
>> Line: 21 | ||
>> UNSAFE_CAST | ||
>> Casting "Variant" to "Node" is unsafe. |
4 changes: 4 additions & 0 deletions
4
modules/gdscript/tests/scripts/runtime/errors/cast_freed_object.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 node := Node.new() | ||
node.free() | ||
print(node as Node2D) |
6 changes: 6 additions & 0 deletions
6
modules/gdscript/tests/scripts/runtime/errors/cast_freed_object.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/cast_freed_object.gd | ||
>> 4 | ||
>> Trying to cast a freed object. |
4 changes: 4 additions & 0 deletions
4
modules/gdscript/tests/scripts/runtime/errors/cast_int_to_array.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 integer: Variant = 1 | ||
@warning_ignore("unsafe_cast") | ||
print(integer as Array) |
6 changes: 6 additions & 0 deletions
6
modules/gdscript/tests/scripts/runtime/errors/cast_int_to_array.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/cast_int_to_array.gd | ||
>> 4 | ||
>> Invalid cast: could not convert value to 'Array'. |
4 changes: 4 additions & 0 deletions
4
modules/gdscript/tests/scripts/runtime/errors/cast_int_to_object.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 integer: Variant = 1 | ||
@warning_ignore("unsafe_cast") | ||
print(integer as Node) |
6 changes: 6 additions & 0 deletions
6
modules/gdscript/tests/scripts/runtime/errors/cast_int_to_object.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/cast_int_to_object.gd | ||
>> 4 | ||
>> Invalid cast: can't convert a non-object value to an object type. |
4 changes: 4 additions & 0 deletions
4
modules/gdscript/tests/scripts/runtime/errors/cast_object_to_int.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 object: Variant = RefCounted.new() | ||
@warning_ignore("unsafe_cast") | ||
print(object as int) |
6 changes: 6 additions & 0 deletions
6
modules/gdscript/tests/scripts/runtime/errors/cast_object_to_int.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/cast_object_to_int.gd | ||
>> 4 | ||
>> Invalid cast: could not convert value to 'int'. |
24 changes: 24 additions & 0 deletions
24
modules/gdscript/tests/scripts/runtime/features/type_casting.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,24 @@ | ||
func print_value(value: Variant) -> void: | ||
if value is Object: | ||
@warning_ignore("unsafe_method_access") | ||
print("<%s>" % value.get_class()) | ||
else: | ||
print(var_to_str(value)) | ||
|
||
func test(): | ||
var int_value := 1 | ||
print_value(int_value as Variant) | ||
print_value(int_value as int) | ||
print_value(int_value as float) | ||
|
||
var node_value := Node.new() | ||
print_value(node_value as Variant) | ||
print_value(node_value as Object) | ||
print_value(node_value as Node) | ||
print_value(node_value as Node2D) | ||
node_value.free() | ||
|
||
var null_value = null | ||
print_value(null_value as Variant) | ||
@warning_ignore("unsafe_cast") | ||
print_value(null_value as Node) |
10 changes: 10 additions & 0 deletions
10
modules/gdscript/tests/scripts/runtime/features/type_casting.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,10 @@ | ||
GDTEST_OK | ||
1 | ||
1 | ||
1.0 | ||
<Node> | ||
<Node> | ||
<Node> | ||
null | ||
null | ||
null |