diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-09 22:24:55 +0200 |
|---|---|---|
| committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-09 22:24:55 +0200 |
| commit | f8ca571efe3075625dcb976c0da3c6c18a0fb1ef (patch) | |
| tree | 5dc1631497db503523843c63699249424d8b2e01 /modules/gdscript/tests/scripts/runtime/features | |
| parent | a7b860250f305f6cbaf61c30f232ff3bbdfdda0b (diff) | |
| parent | 6e996a597fca1181436816a82cced6b8cf34f280 (diff) | |
| download | redot-engine-f8ca571efe3075625dcb976c0da3c6c18a0fb1ef.tar.gz | |
Merge pull request #84043 from dalexeev/gds-fix-unsafe-cast-warning
GDScript: Fix `UNSAFE_CAST` warning
Diffstat (limited to 'modules/gdscript/tests/scripts/runtime/features')
| -rw-r--r-- | modules/gdscript/tests/scripts/runtime/features/type_casting.gd | 24 | ||||
| -rw-r--r-- | modules/gdscript/tests/scripts/runtime/features/type_casting.out | 10 |
2 files changed, 34 insertions, 0 deletions
diff --git a/modules/gdscript/tests/scripts/runtime/features/type_casting.gd b/modules/gdscript/tests/scripts/runtime/features/type_casting.gd new file mode 100644 index 0000000000..c63ea16c32 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/type_casting.gd @@ -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) diff --git a/modules/gdscript/tests/scripts/runtime/features/type_casting.out b/modules/gdscript/tests/scripts/runtime/features/type_casting.out new file mode 100644 index 0000000000..7da5a4c0a4 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/type_casting.out @@ -0,0 +1,10 @@ +GDTEST_OK +1 +1 +1.0 +<Node> +<Node> +<Node> +null +null +null |
