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

Don't allow weaker return type in overriden method #79765

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions modules/gdscript/gdscript_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,8 @@ void GDScriptAnalyzer::resolve_function_signature(GDScriptParser::FunctionNode *
} else {
valid = valid && is_type_compatible(parent_return_type, return_type);
}
} else if (!parent_return_type.is_variant() && !parent_return_type.is_void()) {
valid = false;
}

int par_count_diff = p_function->parameters.size() - parameters_types.size();
Expand Down
1 change: 1 addition & 0 deletions modules/gdscript/gdscript_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class GDScriptParser {
_FORCE_INLINE_ bool is_resolving() const { return kind == RESOLVING; }
_FORCE_INLINE_ bool has_no_type() const { return type_source == UNDETECTED; }
_FORCE_INLINE_ bool is_variant() const { return kind == VARIANT || kind == RESOLVING || kind == UNRESOLVED; }
_FORCE_INLINE_ bool is_void() const { return kind == BUILTIN && builtin_type == Variant::NIL; }
_FORCE_INLINE_ bool is_hard_type() const { return type_source > INFERRED; }

String to_string() const;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Parent:
func override_me() -> bool:
return true

class Child extends Parent:
func override_me():
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
The function signature doesn't match the parent. Parent signature is "override_me() -> bool".
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Parent:
func override_me() -> bool:
return true

class Child extends Parent:
func override_me() -> int:
return 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
The function signature doesn't match the parent. Parent signature is "override_me() -> bool".
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Parent:
func override_me() -> Variant:
return true

class Child extends Parent:
func override_me():
pass

func test():
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GDTEST_OK
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Parent:
func override_me() -> void:
pass

class Child extends Parent:
func override_me():
pass

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

class Child extends Parent:
func override_me() -> bool:
return true

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