You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-13 13:31:48 +00:00
GDScript: Adjust STATIC_CALLED_ON_INSTANCE warning to not default to the native type, and to not trigger on self-calls
Not defaulting to the native type rationale: 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. Not triggering on self-calls rationale: Found in PR comment https://github.com/godotengine/godot/pull/85918#issuecomment-1935864459 ``` static func example(): pass func example2(): example() # self-call on static function ``` Disabling this warning on self-calls is: * Consistent with other languages * Important for anonymous classes (where the output code is unusable)
This commit is contained in:
@@ -1,11 +1,23 @@
|
||||
class Player:
|
||||
var x = 3
|
||||
class_name TestStaticCalledOnInstance
|
||||
|
||||
class Inner:
|
||||
static func static_func():
|
||||
pass
|
||||
|
||||
static func static_func():
|
||||
pass
|
||||
|
||||
func test():
|
||||
# These should not emit a warning.
|
||||
var _player = Player.new()
|
||||
print(String.num_uint64(8589934592)) # 2 ^ 33
|
||||
print(String.num_uint64(8589934592))
|
||||
var some_string := String()
|
||||
print(some_string.num_uint64(8589934592)) # Warning.
|
||||
|
||||
# This should emit a warning.
|
||||
var some_string = String()
|
||||
print(some_string.num_uint64(8589934592)) # 2 ^ 33
|
||||
TestStaticCalledOnInstance.static_func()
|
||||
static_func()
|
||||
self.static_func()
|
||||
var other := TestStaticCalledOnInstance.new()
|
||||
other.static_func() # Warning.
|
||||
|
||||
Inner.static_func()
|
||||
var inner := Inner.new()
|
||||
inner.static_func() # Warning.
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
GDTEST_OK
|
||||
>> WARNING
|
||||
>> Line: 11
|
||||
>> Line: 13
|
||||
>> STATIC_CALLED_ON_INSTANCE
|
||||
>> The function "num_uint64()" is a static function but was called from an instance. Instead, it should be directly called from the type: "String.num_uint64()".
|
||||
>> WARNING
|
||||
>> Line: 19
|
||||
>> STATIC_CALLED_ON_INSTANCE
|
||||
>> The function "static_func()" is a static function but was called from an instance. Instead, it should be directly called from the type: "TestStaticCalledOnInstance.static_func()".
|
||||
>> WARNING
|
||||
>> Line: 23
|
||||
>> STATIC_CALLED_ON_INSTANCE
|
||||
>> The function "static_func()" is a static function but was called from an instance. Instead, it should be directly called from the type: "Inner.static_func()".
|
||||
8589934592
|
||||
8589934592
|
||||
|
||||
Reference in New Issue
Block a user