Skip to content

Commit

Permalink
GDScript: do not warn of return value discarded for super() inside _i…
Browse files Browse the repository at this point in the history
…nit()

DO NOT BATCH MERGE WITH godotengine#77324, WILL RESULT IN BROKEN CI

Currently, calling super() inside _init() throws a
RETURN_VALUE_DISCARDED warning. The analyzer identifies super() as being a
constructor, which therefore returns an object of the relevant class.
However, super() isn't really a constructor by itself: in this case, it
is _part_ of the constructor, and so doesn't "return" a value.

A test case for this is already in godotengine#77324, which contains the warning. I
am duplicating it here, without the warning, and it should conflict with
the other PR.
  • Loading branch information
anvilfolk committed May 22, 2023
1 parent 809a982 commit 25c9083
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions modules/gdscript/gdscript_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3122,7 +3122,8 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a
}

#ifdef DEBUG_ENABLED
if (p_is_root && return_type.kind != GDScriptParser::DataType::UNRESOLVED && return_type.builtin_type != Variant::NIL) {
if (p_is_root && return_type.kind != GDScriptParser::DataType::UNRESOLVED && return_type.builtin_type != Variant::NIL &&
!(p_call->is_super && p_call->function_name == GDScriptLanguage::get_singleton()->strings._init)) {
parser->push_warning(p_call, GDScriptWarning::RETURN_VALUE_DISCARDED, p_call->function_name);
}

Expand Down Expand Up @@ -4710,7 +4711,7 @@ bool GDScriptAnalyzer::get_function_signature(GDScriptParser::Node *p_source, bo
}

if (p_is_constructor) {
function_name = "_init";
function_name = GDScriptLanguage::get_singleton()->strings._init;
r_static = true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class TestOne:
func _init():
pass

class TestTwo extends TestOne:
func _init():
super()

func test():
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GDTEST_OK

0 comments on commit 25c9083

Please sign in to comment.