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

Editor auto-completion/error-checking for preloaded classes is partially non-functional #104494

Open
SilverLPs opened this issue Mar 22, 2025 · 3 comments

Comments

@SilverLPs
Copy link

Tested versions

  • Reproducable in v4.3.stable.official [77dcf97]
  • (Also reproducable in the current stable 4.4 but I don't really use this version yet)

System information

Godot v4.3.stable - Ubuntu 24.04.2 LTS 24.04 - X11 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3050 Ti Laptop GPU - AMD Ryzen 5 5600H with Radeon Graphics (12 Threads)

Issue description

Functions in a subclass calling other static functions/variables in differents scripts/classes won't error check correctly.

  • Wrong calls of an existing function/variable (i.e. wrong parameters/arguments) are correctly recognized as an error by the Editor.
  • Calling non existing static functions/variables in another class/script is not seen as an error and will then only crash at runtime.
  • When writing a function in a subclass, auto-completion for values in an enum of another script/class won't work correctly.

The fact, that the Editor is able to spot wrongly called existing functions but not non-existing functions, made me think this is a bug in the Editor and not expected behaviour, please correct me if I'm wrong.

The provided screenshot highlights only one of the problematic scenarios. I described more of them in the comments in class_a.gd

Image

Steps to reproduce

You can just download and open the testscenario that I created for this issue.

In class_a.gd the class_b.gd is loaded via preload and I made multiple test functions in class_a with respective comments that describe everything that does or does not work regarding the Editors auto-correction/error checking issues I described.

Minimal reproduction project (MRP)

https://github.com/SilverLPs/godot-editorbug or the zip file below

godot-editorbug-master.zip

@HolonProduction
Copy link
Member

HolonProduction commented Mar 23, 2025

Everything seems to work fine, if you actually give the variable a type, by using := instead of =, or by using const instead of static var.

If you use an untyped variable, Godot will be quite lenient with error checking, if you don't want this, you can enable additional checks in the project settings. With "Unsafe method access" set to error the non-existing method is marked as error.

"Unsafe property access" doesn't seem to work in this scenario this is probably actually a bug. (Or it is just an inconsistency, I'm not sure in how far those warnings actually should work with untyped code, because in theory you could reasign the variable at any point which would make everything an invalid call).

@SilverLPs
Copy link
Author

@HolonProduction Thx for your answer.

Regarding your first solution:

Using static var class_b := preload("res://class_b.gd") instead of static var class_b = preload("res://class_b.gd") actually solves all of the issues with error checking and auto completion that I described in this issue.
With the exception of static vars in the called class (class_b). As you can see in my static func print_nonexisting_teststring function in class_a, the errorchecking still doesn't work, when a non-existing variable is called, even tho the same errorchecking now works as expected when calling a non-existing function...

typeof/type_string shows, that := gives the static var the type Object.
Interestingly, setting the type Object manually with this code, does not solve the issue and the error checking and auto completion problems persist:
static var class_b: Object = preload("res://class_b.gd")

Maybe := does something different then : Object =

However I don't know if the behaviour of the remaining scenarios is as intended/expected or actually something that would count as a bug. As the behaviour is still very inconsistent (meaning with := non-existing vars are not recognized by the errorchecking but non-existing function are recognized), I think this could very well still be unexpected/unintended behaviour by the editor.

Regarding your second solution:

Using const all of the issues with errorchecking/autocompletion that I described, are solved, even without :=
I don't know why using const correctly enables the errorchecking/autocompletion while it is only working partially with static var.

Your solutions are at least a very good workaround for the problem, I can easily work with that, so thank you very much!

@HolonProduction
Copy link
Member

typeof/type_string shows, that := gives the static var the type Object. Interestingly, setting the type Object manually with this code, does not solve the issue and the error checking and auto completion problems persist: static var class_b: Object = preload("res://class_b.gd")

Maybe := does something different then : Object =

Godot's type system is a bit complicated. Typeof only gives you the Variant type. All native types (e.g. Node) are Objects. Still internally the variable is not only an Object there is also information on it's native type, Script in this case and the script type res://class_b.gd. So it is not the same as writing : Object. In fact for preloaded scripts there is no way to give an equivalent explicit type since the script type information would get lost.

However I don't know if the behavior of the remaining scenarios is as intended/expected or actually something that would count as a bug. As the behavior is still very inconsistent

Agree, this seems inconsistent but I don't know what the intended behavior is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: For team assessment
Development

No branches or pull requests

3 participants