godot
godot copied to clipboard
GDScript: Adjust `STATIC_CALLED_ON_INSTANCE` warning to not force native type
Defaulting to the native type is less than useful, as:
- There are very few native types that are extensible and have static methods.
- Defaulting to the native type does not account for a method being script-defined.
While the "real fix" would be to carefully track the source of the method, the get_function_signature method is already complicated enough.
This will at least ensure the resulting code should always be valid.
This PR was written after seeing the following warning:
* W 0:00:00:0542 The function "get_absolute_z_index()" is a static function but was called from an instance. Instead, it should be directly called from the type: "Node2D.get_absolute_z_index()".
Where get_absolute_z_index()
was a static function declared in a script (and thus did not exist in Node2D, and thus the given code did not work)
- Bugsquad edit: Fixes #74397.
Note that for non-global classes the warning will suggest invalid code.
Note that for non-global classes the warning will suggest invalid code.
Example, please? I'm not sure what constitutes a "non-global class" in this case.
Example, please? I'm not sure what constitutes a "non-global class" in this case.
Note that this would be wrong on the current master also, it would show EditorScript.static_func()
which isn't a valid way to call it.
We can either accept this as small improvement or work on a proper fix that finds the origin of method.
PS: I wonder if we should even emit this warning with a direct call for a function in the same class. If it does not have class_name
it is quite cumbersome to avoid this warning.
I've amended my commit on the basis of that other languages don't warn for these kinds of self-calls to static functions.
There are more examples and counter-examples one could add involving self
and var x := self
and so forth, but they seem contrived...
Thanks!