Skip to content
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

GDScript 2.0 type introspection is broken #59696

Closed
Uniformbuffer3 opened this issue Mar 30, 2022 · 4 comments
Closed

GDScript 2.0 type introspection is broken #59696

Uniformbuffer3 opened this issue Mar 30, 2022 · 4 comments

Comments

@Uniformbuffer3
Copy link

Uniformbuffer3 commented Mar 30, 2022

Godot version

v4.0.alpha.custom_build [482cdea] (i'm recompiling it daily)

System information

Linux PopOS Nvidia GTX 850M Proprietary driver using the Godot 4 Vulkan cluster backend

Issue description

GDScript 2.0 type introspection only works on variables with engine defined types.
When trying to get the type of variable with an user defined type, the class_name is empty (while the type is still correctly reported as TYPE_OBJECT)

When trying to get the types of a user defined function, all the types are not reported correctly, they are all setted as type: 0 with empty class_name. This happen on both user and engine defines types. Engine defined functions report their types correctly.

There are many opened issue that i think are caused by this problem, i report some i found:
#54284
#21789

Steps to reproduce

Create a script and attach it to a Node, than add the following code and run it:

Minimal reproduction project

extends Node

class UserDefinedType extends Node:
	pass

var engine_defined_type: Button
var user_defined_type: UserDefinedType

func user_defined_function(value1: int,value2: float)->StringName:
	return StringName("Hello!")

func _ready():
	print("Properties")
	for property in get_property_list():
		if property.name == "engine_defined_type" or property.name == "user_defined_type":
			print(property)
			print()
	print()
	print("Methods")
	for method in get_method_list():
		if method.name == "user_defined_function" or method.name == "add_child":
			print(method)
			print()

This should print something like:

Properties
{name:engine_defined_type, class_name:Button, type:21, hint:0, hint_string:, usage:8192}

{name:user_defined_type, class_name:, type:21, hint:0, hint_string:, usage:8192}


Methods
{name:add_child, args:[{name:node, class_name:Node, type:21, hint:0, hint_string:, usage:7}, {name:legible_unique_name, class_name:, type:1, hint:0, hint_string:, usage:7}, {name:internal, class_name:Node.InternalMode, type:2, hint:0, hint_string:, usage:262151}], default_args:[false, 0], flags:1, id:2900, return:{name:, class_name:, type:0, hint:0, hint_string:, usage:7}}

{name:user_defined_function, args:[{name:arg0, class_name:, type:0, hint:0, hint_string:, usage:7}, {name:arg1, class_name:, type:0, hint:0, hint_string:, usage:7}], default_args:[], flags:65, id:0, return:{name:, class_name:, type:0, hint:0, hint_string:, usage:7}}

showing that user defined types are not reported correcty, indeed class_name is empty, while on user defined functions all the types are simply broken, even if all the parameters and the return type are different, they are all reported as type: 0.
To be noticed also that on user defined methods, all the parameters names are replaced with arg0, arg1... while on the engine defined functions, this does not happen.

@Uniformbuffer3
Copy link
Author

Uniformbuffer3 commented Mar 30, 2022

I know i shouldn't add a second problem to the same issue, but i'm pretty sure they are related and solving the issue will probably fix both, so knowing also this problem could be helpful to debugging: it is not possible to overload any engine defined method.

Adding a code like this:

func add_child(node: Node, legible_unique_name: bool, internal: InternalMode)->void:
	pass

will throws:

Parse Error: The function signature doesn't match the parent. Parent signature is "void add_child(Node, bool = default, int)".
  modules/gdscript/gdscript.cpp:870 - Method/function failed. Returning: ERR_PARSE_ERROR

The method signature match, i have also tried to use int instead of InternalMode (that is an enum, so just an int value), but the result is the same.
I think the reason is simply that, since user defined methods report wrong parameters and return types, they will always mismatch with the engine defined methods, that are instead reported correctly.
Also i think this issue is happening for a while, i have initially noticed it when the feature that checks the method signature for correct overloading has been introduced, but only now i understood the root of the problem.

@Calinou
Copy link
Member

Calinou commented Mar 30, 2022

it is not possible to overload any engine defined method.

See also #55024.

@Uniformbuffer3
Copy link
Author

Uniformbuffer3 commented Apr 12, 2022

Recent Godot 4 updates broke the enum type introspection too, i'm adding it here because i think the issue is still the same, just another effect of the same problem:

enum TestEnum {
	Entry1,
	Entry2,
	Entry3
}

func get_enum_entry()->TestEnum:
	return TestEnum.Entry1

func _ready():
	print(get_enum_entry())

The result of this code is a runtime error when running the get_enum_entry() function:
Trying to return value of type "int" from a function which the return type is "Dictionary".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants