diff options
author | Dmitrii Maganov <vonagam@gmail.com> | 2023-01-24 23:21:54 +0200 |
---|---|---|
committer | Dmitrii Maganov <vonagam@gmail.com> | 2023-01-28 23:56:07 +0200 |
commit | 6194a7e0fa4cb15b21bc81005f1f05f331dfb214 (patch) | |
tree | e0592f1e79ab0772cfdcd0cb7bd34216b9e4ebf5 /modules/gdscript/tests/scripts | |
parent | 218bef90af2091afde3b1be816c87286c194a2a8 (diff) |
GDScript: Fix implicit conversions for function returns
Diffstat (limited to 'modules/gdscript/tests/scripts')
-rw-r--r-- | modules/gdscript/tests/scripts/analyzer/features/return_conversions.gd | 34 | ||||
-rw-r--r-- | modules/gdscript/tests/scripts/analyzer/features/return_conversions.out | 2 |
2 files changed, 36 insertions, 0 deletions
diff --git a/modules/gdscript/tests/scripts/analyzer/features/return_conversions.gd b/modules/gdscript/tests/scripts/analyzer/features/return_conversions.gd new file mode 100644 index 0000000000..0b1576e66e --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/return_conversions.gd @@ -0,0 +1,34 @@ +func convert_literal_int_to_float() -> float: return 76 +func convert_arg_int_to_float(arg: int) -> float: return arg +func convert_var_int_to_float() -> float: var number := 59; return number + +func convert_literal_array_to_packed() -> PackedStringArray: return ['46'] +func convert_arg_array_to_packed(arg: Array) -> PackedStringArray: return arg +func convert_var_array_to_packed() -> PackedStringArray: var array := ['79']; return array + +func test(): + var converted_literal_int := convert_literal_int_to_float() + assert(typeof(converted_literal_int) == TYPE_FLOAT) + assert(converted_literal_int == 76.0) + + var converted_arg_int := convert_arg_int_to_float(36) + assert(typeof(converted_arg_int) == TYPE_FLOAT) + assert(converted_arg_int == 36.0) + + var converted_var_int := convert_var_int_to_float() + assert(typeof(converted_var_int) == TYPE_FLOAT) + assert(converted_var_int == 59.0) + + var converted_literal_array := convert_literal_array_to_packed() + assert(typeof(converted_literal_array) == TYPE_PACKED_STRING_ARRAY) + assert(str(converted_literal_array) == '["46"]') + + var converted_arg_array := convert_arg_array_to_packed(['91']) + assert(typeof(converted_arg_array) == TYPE_PACKED_STRING_ARRAY) + assert(str(converted_arg_array) == '["91"]') + + var converted_var_array := convert_var_array_to_packed() + assert(typeof(converted_var_array) == TYPE_PACKED_STRING_ARRAY) + assert(str(converted_var_array) == '["79"]') + + print('ok') diff --git a/modules/gdscript/tests/scripts/analyzer/features/return_conversions.out b/modules/gdscript/tests/scripts/analyzer/features/return_conversions.out new file mode 100644 index 0000000000..1b47ed10dc --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/return_conversions.out @@ -0,0 +1,2 @@ +GDTEST_OK +ok |