godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.22k stars 21.22k forks source link

Binding to a callable that accepts array as an argument fails with "Invalid type in function '...' Cannot convert argument 1 from Callable to Array" #92215

Open smedelyan opened 6 months ago

smedelyan commented 6 months ago

Tested versions

4.2.4

System information

Windows - Godot 4.2.4

Issue description

I can't bind arguments to a callable that accepts single array as argument

Steps to reproduce

Make this code run:

    func _ready() -> void:
        var callable: Callable = test.bind(["one", "two", "three"])
        callable.call()

    func test(arr: Array[String]) -> void:
        for e in arr:
            print(e)

It will fail with the error like Invalid type in function '...' Cannot convert argument 1 from Callable to Array

Minimal reproduction project (MRP)

N/A

AThousandShips commented 6 months ago

This is specifically for Array[String] and that the passed argument isn't an Array[String] but just an Array, if you use:

    func _ready() -> void:
        var arr : Array[String] = ["one", "two", "three"]
        var callable: Callable = test.bind(arr)
        callable.call()

    func test(arr: Array[String]) -> void:
        for e in arr:
            print(e)

It works, this is related to general issues with typed arrays, unsure what the specific error is here, the "Callable to Array" is likely a separate issue with how the error printing is done

smedelyan commented 6 months ago

Thank you very much 🐳 My issue is solved now. Feel free to close this issue or keep it open / create a new one for the error printing

AThousandShips commented 6 months ago

It's still an issue that it doesn't handle the conversion properly, even without the weirdness of the error message, might already be reported though

Vlad-Zumer commented 5 months ago

Same core issue as #91048, Packed Arrays do not coerce to typed arrays, only to Array.

func _ready():
    var callableOK: Callable = TestOK.bind(["one", "two", "three"])
    callableOK.call()

    #var callableProblem: Callable = TestProblem.bind(["one", "two", "three"])
    #callableProblem.call()

func TestProblem(arr: Array[String]) -> void:
    print("TestProblem arr: %s" % arr)

func TestOK(arr: PackedStringArray) -> void:
    print("TestOK arr: %s" % arr)