godotengine / godotengine/godot
PackedStringArrays do not consistently coerce into Array[String]
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
- Reproducible in: 4.3dev5
### System information
Godot v4.3.dev5 - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1660 Ti (NVIDIA; 31.0.15.1640) - AMD Ryzen 7 4800H with Radeon Graphics (16 Threads)
### Issue description
I know this is slightly improper but in this case starting with the code seems easiest:
```gdscript
extends Node
func _ready():
testA(PackedStringArray(["test", "string"]))
func testA(string_array: Array[String]):
testB(string_array)
func testB(string_array: Array[String]):
print(string_array)
```
which will result in the error on line 6:
`Invalid type in function 'testB' in base 'Node (test.gd)'. The array of argument 1 (Array) does not have the same element type as the expected typed array argument.`
The weird part being that function A was able to accept the `PackedStringArray` as if it were `Array[String]`. However, function B fails with an unhelpful message claiming it's an `Array`. If you change B to take a `PackedStringArray` it all works.
### Steps to reproduce
Generate a PackedStringArray somehow (.split() or the constructor are tested)
Pass it through more than one function
### Minimal reproduction project (MRP)
MRP included just in case it saves you a few seconds, but you just have to put a node in with the script attached:
[stringarray.zip](https://github.com/godotengine/godot/files/15074510/stringarray.zip)
Contributor guide
Assessment
This issue has not been assessed yet.