1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

GDScript: Replace abstract keyword with @abstract annotation

Co-authored-by: Danil Alexeev <dalexeev12@yandex.ru>
This commit is contained in:
Aaron Franke
2025-06-19 04:53:15 -07:00
parent 88b9932ce1
commit 1085200f51
31 changed files with 179 additions and 197 deletions

View File

@@ -1,15 +1,15 @@
abstract class AbstractClass:
abstract func some_func()
@abstract class AbstractClass:
@abstract func some_func()
class ImplementedClass extends AbstractClass:
func some_func():
pass
abstract class AbstractClassAgain extends ImplementedClass:
abstract func some_func()
@abstract class AbstractClassAgain extends ImplementedClass:
@abstract func some_func()
class Test1:
abstract func some_func()
@abstract func some_func()
class Test2 extends AbstractClass:
pass
@@ -24,5 +24,18 @@ class Test4 extends AbstractClass:
func other_func():
super.some_func()
@abstract class A:
@abstract @abstract func abstract_dup()
# An abstract function cannot have a body.
@abstract func abstract_bodyful():
pass
# A static function cannot be marked as `@abstract`.
@abstract static func abstract_stat()
@abstract @abstract class DuplicateAbstract:
pass
func test():
pass

View File

@@ -1,6 +1,11 @@
GDTEST_ANALYZER_ERROR
>> ERROR at line 11: Class "Test1" is not abstract but contains abstract methods. Mark the class as abstract or remove "abstract" from all methods in this class.
>> ERROR at line 14: Class "Test2" must implement "AbstractClass.some_func()" and other inherited abstract methods or be marked as abstract.
>> ERROR at line 17: Class "Test3" must implement "AbstractClassAgain.some_func()" and other inherited abstract methods or be marked as abstract.
>> ERROR at line 37: "@abstract" annotation can only be used once per class.
>> ERROR at line 28: "@abstract" annotation can only be used once per function.
>> ERROR at line 35: "@abstract" annotation cannot be applied to static functions.
>> ERROR at line 11: Class "Test1" is not abstract but contains abstract methods. Mark the class as "@abstract" or remove "@abstract" from all methods in this class.
>> ERROR at line 14: Class "Test2" must implement "AbstractClass.some_func()" and other inherited abstract methods or be marked as "@abstract".
>> ERROR at line 17: Class "Test3" must implement "AbstractClassAgain.some_func()" and other inherited abstract methods or be marked as "@abstract".
>> ERROR at line 22: Cannot call the parent class' abstract function "some_func()" because it hasn't been defined.
>> ERROR at line 25: Cannot call the parent class' abstract function "some_func()" because it hasn't been defined.
>> ERROR at line 32: Abstract function cannot have a body.
>> ERROR at line 35: A function must either have a ":" followed by a body, or be marked as "@abstract".

View File

@@ -2,7 +2,7 @@ extends RefCounted
const AbstractScript = preload("./construct_abstract_script.notest.gd")
abstract class AbstractClass:
@abstract class AbstractClass:
pass
func test():

View File

@@ -1 +1 @@
abstract class_name AbstractScript
@abstract class_name AbstractScript

View File

@@ -8,7 +8,7 @@ class B extends A:
class C extends CanvasItem:
pass
abstract class X:
@abstract class X:
pass
class Y extends X:

View File

@@ -1,5 +1,5 @@
abstract class A:
abstract func test(x: int) -> void
@abstract class A:
@abstract func test(x: int) -> void
class B extends A:
func

View File

@@ -1,8 +0,0 @@
extends RefCounted
abstract class A:
abstract func f():
pass
func test():
pass

View File

@@ -1,2 +0,0 @@
GDTEST_PARSER_ERROR
Expected end of statement after abstract function declaration, found ":" instead.

View File

@@ -1,8 +0,0 @@
extends RefCounted
abstract class A:
# Currently, an abstract function cannot be static.
abstract static func f()
func test():
pass

View File

@@ -1,2 +0,0 @@
GDTEST_PARSER_ERROR
Expected "class" or "func" after "abstract".

View File

@@ -1,2 +1,2 @@
GDTEST_PARSER_ERROR
Expected ":" after function declaration.
Expected end of statement after bodyless function declaration, found "{" instead.

View File

@@ -1,7 +0,0 @@
extends RefCounted
abstract abstract class A:
pass
func test():
pass

View File

@@ -1,2 +0,0 @@
GDTEST_PARSER_ERROR
Expected "class_name", "extends", "class", or "func" after "abstract".

View File

@@ -1,7 +0,0 @@
extends RefCounted
abstract class A:
abstract abstract func f()
func test():
pass

View File

@@ -1,2 +0,0 @@
GDTEST_PARSER_ERROR
Expected "class" or "func" after "abstract".

View File

@@ -0,0 +1,3 @@
# No colon --v
var f = func () -> void
pass

View File

@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected ":" after lambda declaration.

View File

@@ -1,8 +0,0 @@
extends RefCounted
abstract class A:
# Currently, an abstract function cannot be static.
static abstract func f()
func test():
pass

View File

@@ -1,2 +0,0 @@
GDTEST_PARSER_ERROR
Expected "func" or "var" after "static".

View File

@@ -1,18 +1,18 @@
abstract class A:
abstract func get_text_1() -> String
abstract func get_text_2() -> String
@abstract class A:
@abstract func get_text_1() -> String
@abstract func get_text_2() -> String
# No `UNUSED_PARAMETER` warning.
abstract func func_with_param(param: int) -> int
abstract func func_with_rest_param(...args: Array) -> int
abstract func func_with_semicolon() -> int;
abstract func func_1() -> int; abstract func func_2() -> int
abstract func func_without_return_type()
@abstract func func_with_param(param: int) -> int
@abstract func func_with_rest_param(...args: Array) -> int
@abstract func func_with_semicolon() -> int;
@abstract func func_1() -> int; @abstract func func_2() -> int
@abstract func func_without_return_type()
func print_text_1() -> void:
print(get_text_1())
abstract class B extends A:
@abstract class B extends A:
func get_text_1() -> String:
return "text_1b"
@@ -30,8 +30,8 @@ class C extends B:
func func_2() -> int: return 0
func func_without_return_type(): pass
abstract class D extends C:
abstract func get_text_1() -> String
@abstract class D extends C:
@abstract func get_text_1() -> String
func get_text_2() -> String:
return super() + " text_2d"

View File

@@ -2,9 +2,9 @@
@warning_ignore_start("unused_signal")
abstract class A:
abstract func test_abstract_func_1()
abstract func test_abstract_func_2()
@abstract class A:
@abstract func test_abstract_func_1()
@abstract func test_abstract_func_2()
func test_override_func_1(): pass
func test_override_func_2(): pass

View File

@@ -32,8 +32,8 @@ func test_override_func_1() -> void
func test_override_func_2() -> void
func test_func_b1() -> void
func test_func_b2() -> void
abstract func test_abstract_func_1() -> void
abstract func test_abstract_func_2() -> void
@abstract func test_abstract_func_1() -> void
@abstract func test_abstract_func_2() -> void
func test_override_func_1() -> void
func test_override_func_2() -> void
--- C ---
@@ -53,8 +53,8 @@ func test_override_func_1() -> void
func test_override_func_2() -> void
func test_func_b1() -> void
func test_func_b2() -> void
abstract func test_abstract_func_1() -> void
abstract func test_abstract_func_2() -> void
@abstract func test_abstract_func_1() -> void
@abstract func test_abstract_func_2() -> void
func test_override_func_1() -> void
func test_override_func_2() -> void
=== Signals ===

View File

@@ -101,7 +101,7 @@ static func print_property_extended_info(property: Dictionary, base: Object = nu
static func get_method_signature(method: Dictionary, is_signal: bool = false) -> String:
var result: String = ""
if method.flags & METHOD_FLAG_VIRTUAL_REQUIRED:
result += "abstract "
result += "@abstract "
if method.flags & METHOD_FLAG_STATIC:
result += "static "
result += ("signal " if is_signal else "func ") + method.name + "("