diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2023-06-13 18:54:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-13 18:54:19 +0200 |
commit | eb86dabee07e8dfce3b06cbd557b50b74afd3d6c (patch) | |
tree | 287ad53e39c69f8160193ec6c6308cb946efe572 | |
parent | 49243a9a9816b334002f7d73d9e940d00b49158d (diff) | |
parent | 3bf72be62530fa69235d549f3a402061bcd7ed38 (diff) | |
download | redot-engine-eb86dabee07e8dfce3b06cbd557b50b74afd3d6c.tar.gz |
Merge pull request #77151 from dalexeev/gds-fix-call-static-from-non-static
GDScript: Fix calling static func from non-static is allowed
3 files changed, 14 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 96bd8aafad..029676e404 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -1692,6 +1692,9 @@ void GDScriptAnalyzer::resolve_function_body(GDScriptParser::FunctionNode *p_fun GDScriptParser::FunctionNode *previous_function = parser->current_function; parser->current_function = p_function; + bool previous_static_context = static_context; + static_context = p_function->is_static; + resolve_suite(p_function->body); if (!p_function->get_datatype().is_hard_type() && p_function->body->get_datatype().is_set()) { @@ -1707,6 +1710,7 @@ void GDScriptAnalyzer::resolve_function_body(GDScriptParser::FunctionNode *p_fun parser->ignored_warnings = previously_ignored_warnings; #endif parser->current_function = previous_function; + static_context = previous_static_context; } void GDScriptAnalyzer::decide_suite_type(GDScriptParser::Node *p_suite, GDScriptParser::Node *p_statement) { diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static.gd b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static.gd new file mode 100644 index 0000000000..1d8f076857 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static.gd @@ -0,0 +1,8 @@ +static func static_func(): + non_static_func() + +func non_static_func(): + pass + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static.out b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static.out new file mode 100644 index 0000000000..b78f131345 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot call non-static function "non_static_func()" from static function "static_func()". |