-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot cast typed arrays using type hints #72627
Comments
Same issue as #72620 var arr : Array[int] = Array[int](my_dictionary.keys()) It's not implemented yet though. Use |
It is possible to add support for |
Note that:
|
Correction, print( typeof( 1 as float ) == TYPE_FLOAT ) # true
print( typeof( 'a' as StringName ) == TYPE_STRING_NAME ) # true
print( typeof( [ 'a' ] as PackedStringArray ) == TYPE_PACKED_STRING_ARRAY ) # true |
I have the same issue quite often and it is always caused by calling |
I intuitively expected
It's more surprising that Ideally |
Fixes oniksan#38. Given: ``` message Foo { repeated int32 i = 1; repeated string s = 2; repeated Bar b = 3; } ``` Previously godobuf would generate: ``` get_i() -> Array get_s() -> Array get_b() -> Array ``` Now it generates: ``` get_i() -> Array[int] get_s() -> Array[string] get_b() -> Array[Bar] ``` To do this, we must assign a typed array when constructing the PBField. Godot does not currently have a typed array constructor: godotengine/godot#72627 (comment) To work around this, we create a local typed variable, like so: ``` class Test1: func _init(): var __rf_double_default: Array[float] = [] __rf_double = PBField.new("rf_double", PB_DATA_TYPE.DOUBLE, PB_RULE.REPEATED, 23, true, __rf_double_default) ... func get_rf_double() -> Array[float]: return __rf_double.value ```
Godot version
4.0 beta 17
System information
Arch Linux
Issue description
type hints for typed arrays seem to be entirely ignored. The particular use case I am having trouble with seems to be related both to Dictionaries not being typed as mentioned in #56, and to the typed array implementation change in #69248.
Steps to reproduce
Attempt to run the following script, and note that the interpreter complains about trying to assign an Array to an Array[int], despite trying to cast the untyped Array to Array[int] in that very line. Commenting out the lines related to the Array[int] will still leave you with an issue as you get the same error trying to pass an Array into an argument for an Array[String].
Minimal reproduction project
array_casting_from_dictionary.zip
The text was updated successfully, but these errors were encountered: