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

Typehints on inner classes don't recognize the class if created from the GDScript resource #61567

Closed
dsnopek opened this issue May 31, 2022 · 1 comment

Comments

@dsnopek
Copy link
Contributor

dsnopek commented May 31, 2022

Godot version

v4.0.alpha.custom_build.532e253a7

System information

Linux, Vulkan, 1070M

Issue description

I've been working on porting the Nakama client to Godot 4. In Godot 3, it uses this pattern where there's a bunch of "namespaces" (*.gd scripts with lots of inner classes - they are automatically generated from Swagger definitions) and some generic methods that take the inner class as an argument, so that it knows what class to wrap the response from the server in.

Anyway, while working on this, I discovered that typehints on these inner classes don't work (ie. they won't correctly recognize the class as being the class) if they are created from the GDScript resource. I get a runtime error like:

Trying to return value of type "InnerClass1" from a function which the return type is "MyNamespace"

This may be related to issue #61635

Steps to reproduce

I've included a minimal reproduction project below, but here is the key code (from the Main.gd in the project) to illustrate the problem:

extends Node2D

func _ready():
	# This works fine!
	var n = create_normal_class("Normal")
	print (n)
	
	# This gets the runtime error :-(
	var i = create_inner_class("Inner")
	print (i)

func _do_and_create(p_value: String, p_class: GDScript):
	return p_class.new(p_value)

func create_normal_class(p_value: String) -> MyClass:
	return _do_and_create(p_value, MyClass)

func create_inner_class(p_value: String) -> MyNamespace.InnerClass1:
	return _do_and_create(p_value, MyNamespace.InnerClass1)

Minimal reproduction project

godot-4-typehint-bug.zip

@vnen
Copy link
Member

vnen commented Dec 22, 2022

I cannot reproduce this on current master. It might have been fixed with other changes, so I'm closing this. If that's not the case let me know and I'll reopen.

@vnen vnen closed this as completed Dec 22, 2022
@vnen vnen moved this from Todo to Done in GDScript Stabilization Tasks Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants