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: Fix accessing static function as Callable in static context #86088

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: 6 additions & 2 deletions modules/gdscript/gdscript_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,13 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code
if (member.type == GDScriptParser::ClassNode::Member::FUNCTION || member.type == GDScriptParser::ClassNode::Member::SIGNAL) {
// Get like it was a property.
GDScriptCodeGenerator::Address temp = codegen.add_temporary(); // TODO: Get type here.
GDScriptCodeGenerator::Address self(GDScriptCodeGenerator::Address::SELF);

gen->write_get_named(temp, identifier, self);
GDScriptCodeGenerator::Address base(GDScriptCodeGenerator::Address::SELF);
if (member.type == GDScriptParser::ClassNode::Member::FUNCTION && member.function->is_static) {
base = GDScriptCodeGenerator::Address(GDScriptCodeGenerator::Address::CLASS);
}

gen->write_get_named(temp, identifier, base);
return temp;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# GH-79521
# GH-79521, GH-86032

class_name TestStaticMethodAsCallable

static func static_func() -> String:
return "Test"

static func another_static_func():
prints("another_static_func:", static_func.call(), static_func.is_valid())

func test():
var a: Callable = TestStaticMethodAsCallable.static_func
var b: Callable = static_func
prints(a.call(), a.is_valid())
prints(b.call(), b.is_valid())
@warning_ignore("static_called_on_instance")
another_static_func()
TestStaticMethodAsCallable.another_static_func()
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
GDTEST_OK
Test true
Test true
another_static_func: Test true
another_static_func: Test true
Loading