godotengine / godot

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

In tool script, providing constructor that takes typed array with untyped array produces 'Error constructing a GDScriptInstance.' #83823

Open SpadeInTheDirt opened 11 months ago

SpadeInTheDirt commented 11 months ago

Godot version

v4.2.beta.custom_build [fd33c7b32], v4.1.2.stable.official [399c9dc39]

System information

Godot v4.1.2.stable & v4.2.beta - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 (NVIDIA; 31.0.15.3114) - Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz (12 Threads)

Issue description

Passing an untyped array, ie. Array to a constructor that expects a typed array, ex. Array[int] in a tool script causes Error constructing a GDScriptInstance.. I don't know if it should accept it, but it should at least give a better error message.

Specific error messages:

 Error constructing a GDScriptInstance.
 res://something.gd:12 - Invalid type in function 'new' in base 'GDScript'. The array of argument 1 (Array) does not have the same element type as the expected typed array argument.

Steps to reproduce

Load the project or reload the scene containing the tool script to see the error message.

Minimal reproduction project

Test.zip

SpadeInTheDirt commented 11 months ago

You can fix this in the meanwhile by just typing the array you provide to the constructor accordingly.