-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81808 from anvilfolk/super-virtual
GDScript: Add check for `super()` methods not being implemented
- Loading branch information
Showing
5 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
modules/gdscript/tests/scripts/analyzer/errors/virtual_super_not_implemented.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
func _init(): | ||
super() | ||
|
||
func test(): | ||
pass |
2 changes: 2 additions & 0 deletions
2
modules/gdscript/tests/scripts/analyzer/errors/virtual_super_not_implemented.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GDTEST_ANALYZER_ERROR | ||
Cannot call the parent class' virtual function "_init()" because it hasn't been defined. |
21 changes: 21 additions & 0 deletions
21
modules/gdscript/tests/scripts/analyzer/features/virtual_method_implemented.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class BaseClass: | ||
func _get_property_list(): | ||
return {"property" : "definition"} | ||
|
||
class SuperClassMethodsRecognized extends BaseClass: | ||
func _init(): | ||
# Recognizes super class methods. | ||
var _x = _get_property_list() | ||
|
||
class SuperMethodsRecognized extends BaseClass: | ||
func _get_property_list(): | ||
# Recognizes super method. | ||
var result = super() | ||
result["new"] = "new" | ||
return result | ||
|
||
func test(): | ||
var test1 = SuperClassMethodsRecognized.new() | ||
print(test1._get_property_list()) # Calls base class's method. | ||
var test2 = SuperMethodsRecognized.new() | ||
print(test2._get_property_list()) |
3 changes: 3 additions & 0 deletions
3
modules/gdscript/tests/scripts/analyzer/features/virtual_method_implemented.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
GDTEST_OK | ||
{ "property": "definition" } | ||
{ "property": "definition", "new": "new" } |