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 do not recognize function argument types #64915

Closed
bitbrain opened this issue Aug 26, 2022 · 6 comments · Fixed by #68374
Closed

Typehints on inner classes do not recognize function argument types #64915

bitbrain opened this issue Aug 26, 2022 · 6 comments · Fixed by #68374

Comments

@bitbrain
Copy link
Contributor

bitbrain commented Aug 26, 2022

Godot version

9c9b8fc

System information

Windows 10

Issue description

I use a lot of inner classes in my project to structure my data better and in Godot 3.5+ I was able to instantiate an inner class and use it as a function argument type. Attempting this in Godot 4 results in a compilation error:

Invalid type in function '_print_string_value' in base 'Node2D ()'. The Object-derived class of argument 1 (RefCounted (ChildClassA)) is not a subclass of the expected argument class.

This line comes from

err_text = "Invalid type in " + p_where + ". The Object-derived class of argument " + itos(errorarg + 1) + " (" + _get_var_type(argptrs[errorarg]) + ") is not a subclass of the expected argument class.";
and when debugging the project it looks like there is not a real type created but just a RefCounted:
Capture

This might relate to #61567 and #61635 however, they mention very specific use-cases while I am just trying to use the type itself.

Steps to reproduce

Create some inner classes with inheritance and then register that namespace class as a autoload singleton:
Capture2

Attempt to use the inner classes as types:
Capture

Minimal reproduction project

gdscript-inner-classes.zip

@bitbrain bitbrain changed the title Typehints on inner classes are not recognized as method arguments Typehints on inner classes do not recognize function argument types Aug 26, 2022
@olibombardier
Copy link

I have the same issue, the workaround I found was to explicitly convert to the subclass when passing an argument to a method. (_print_string_value(class1 as MyNamespace.MyParentClass) would probably work)

@olibombardier
Copy link

Turns out I was wrong, converting to the subclass returns null. With other corrections I needed to make to convert to Godot 4 I didn't realise that this was the cause of one of my bug. Should I open another bug report? It might be the same problem where some part of gdscript doesn't recognize an instance of a subclass as that

@adamscott
Copy link
Member

This seems, at first glance, linked to #65953, where the base class is not set well. I will try to investigate this.

@lyuma
Copy link
Contributor

lyuma commented Oct 25, 2022

There have been issues with inner classes and type declarations before.
There are also issues I filed last year #47062 and #47063, both of which were fixed by #49105

But I was able to reproduce a similar issue here by referencing an inner class from a different file.

SCRIPT ERROR: Trying to assign value of type '' to a variable of type 'external_type.gd'.
          at: _enter_tree (res://addons/imported_type_test/plugin.gd:14)
SCRIPT ERROR: Trying to assign value of type '' to a variable of type 'inner_classes.gd'.
          at: _enter_tree (res://addons/inner_class_decl/plugin.gd:14)

here's a test project for this if you want to try it (see the versions : Object work fine, but type hints break it):
ImportedTypeDecl.zip

@adamscott
Copy link
Member

@lyuma I can't test right now, but can you test your project against my cyclic references PR #67714? It fixes this issue.

@rune-scape
Copy link
Contributor

tested that #68374 fixes this

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

Successfully merging a pull request may close this issue.

7 participants