1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-12 13:20:55 +00:00

GDScript: Fix issues with typed arrays

This commit is contained in:
Dmitrii Maganov
2022-11-27 09:56:53 +02:00
parent e9de988020
commit 5909f9f075
50 changed files with 959 additions and 555 deletions

View File

@@ -0,0 +1,4 @@
func test():
var basic := [1]
var typed: Array[int] = basic
print('not ok')

View File

@@ -0,0 +1,6 @@
GDTEST_RUNTIME_ERROR
>> SCRIPT ERROR
>> on function: test()
>> runtime/errors/typed_array_assign_basic_to_typed.gd
>> 3
>> Trying to assign an array of type "Array" to a variable of type "Array[int]".

View File

@@ -0,0 +1,4 @@
func test():
var differently: Variant = [1.0] as Array[float]
var typed: Array[int] = differently
print('not ok')

View File

@@ -0,0 +1,6 @@
GDTEST_RUNTIME_ERROR
>> SCRIPT ERROR
>> on function: test()
>> runtime/errors/typed_array_assign_differently_typed.gd
>> 3
>> Trying to assign an array of type "Array[float]" to a variable of type "Array[int]".

View File

@@ -0,0 +1,7 @@
func expect_typed(typed: Array[int]):
print(typed.size())
func test():
var basic := [1]
expect_typed(basic)
print('not ok')

View File

@@ -0,0 +1,6 @@
GDTEST_RUNTIME_ERROR
>> SCRIPT ERROR
>> on function: test()
>> runtime/errors/typed_array_pass_basic_to_typed.gd
>> 6
>> Invalid type in function 'expect_typed' in base 'RefCounted ()'. The array of argument 1 (Array) does not have the same element type as the expected typed array argument.

View File

@@ -0,0 +1,7 @@
func expect_typed(typed: Array[int]):
print(typed.size())
func test():
var differently: Variant = [1.0] as Array[float]
expect_typed(differently)
print('not ok')

View File

@@ -0,0 +1,6 @@
GDTEST_RUNTIME_ERROR
>> SCRIPT ERROR
>> on function: test()
>> runtime/errors/typed_array_pass_differently_to_typed.gd
>> 6
>> Invalid type in function 'expect_typed' in base 'RefCounted ()'. The array of argument 1 (Array[float]) does not have the same element type as the expected typed array argument.

View File

@@ -0,0 +1,6 @@
func test():
var untyped: Variant = 32
var typed: Array[int] = [untyped]
assert(typed.get_typed_builtin() == TYPE_INT)
assert(str(typed) == '[32]')
print('ok')