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

GDScript: Adjust STATIC_CALLED_ON_INSTANCE warning to not force native type #85918

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions modules/gdscript/gdscript_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3360,12 +3360,8 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a
parser->push_warning(p_call, GDScriptWarning::RETURN_VALUE_DISCARDED, p_call->function_name);
}

if (method_flags.has_flag(METHOD_FLAG_STATIC) && !is_constructor && !base_type.is_meta_type && !(is_self && static_context)) {
String caller_type = String(base_type.native_type);

if (caller_type.is_empty()) {
caller_type = base_type.to_string();
}
if (method_flags.has_flag(METHOD_FLAG_STATIC) && !is_constructor && !base_type.is_meta_type && !is_self) {
String caller_type = base_type.to_string();

parser->push_warning(p_call, GDScriptWarning::STATIC_CALLED_ON_INSTANCE, p_call->function_name, caller_type);
}
Expand Down
dalexeev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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.

TestStaticCalledOnInstance.static_func()
static_func()
self.static_func()
var other := TestStaticCalledOnInstance.new()
other.static_func() # Warning.

# This should emit a warning.
var some_string = String()
print(some_string.num_uint64(8589934592)) # 2 ^ 33
Inner.static_func()
var inner := Inner.new()
inner.static_func() # Warning.
dalexeev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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
Loading