From 9507f65e25fd02b1e5817b787afdbef334b964e7 Mon Sep 17 00:00:00 2001 From: Dmitrii Maganov Date: Wed, 28 Dec 2022 07:12:16 +0200 Subject: GDScript: Disallow return with value in void functions --- .../tests/scripts/analyzer/errors/return_null_in_void_func.gd | 2 ++ .../tests/scripts/analyzer/errors/return_null_in_void_func.out | 2 ++ .../tests/scripts/analyzer/errors/return_variant_in_void_func.gd | 4 ++++ .../tests/scripts/analyzer/errors/return_variant_in_void_func.out | 2 ++ .../gdscript/tests/scripts/analyzer/features/return_variant_typed.gd | 5 +++++ .../tests/scripts/analyzer/features/return_variant_typed.out | 2 ++ 6 files changed, 17 insertions(+) create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/return_null_in_void_func.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/return_null_in_void_func.out create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/return_variant_in_void_func.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/return_variant_in_void_func.out create mode 100644 modules/gdscript/tests/scripts/analyzer/features/return_variant_typed.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/features/return_variant_typed.out (limited to 'modules/gdscript/tests/scripts/analyzer') diff --git a/modules/gdscript/tests/scripts/analyzer/errors/return_null_in_void_func.gd b/modules/gdscript/tests/scripts/analyzer/errors/return_null_in_void_func.gd new file mode 100644 index 0000000000..63587942f7 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/return_null_in_void_func.gd @@ -0,0 +1,2 @@ +func test() -> void: + return null diff --git a/modules/gdscript/tests/scripts/analyzer/errors/return_null_in_void_func.out b/modules/gdscript/tests/scripts/analyzer/errors/return_null_in_void_func.out new file mode 100644 index 0000000000..3c09f44ba9 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/return_null_in_void_func.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +A void function cannot return a value. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/return_variant_in_void_func.gd b/modules/gdscript/tests/scripts/analyzer/errors/return_variant_in_void_func.gd new file mode 100644 index 0000000000..0ee4e7ea36 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/return_variant_in_void_func.gd @@ -0,0 +1,4 @@ +func test() -> void: + var a + a = 1 + return a diff --git a/modules/gdscript/tests/scripts/analyzer/errors/return_variant_in_void_func.out b/modules/gdscript/tests/scripts/analyzer/errors/return_variant_in_void_func.out new file mode 100644 index 0000000000..3c09f44ba9 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/return_variant_in_void_func.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +A void function cannot return a value. diff --git a/modules/gdscript/tests/scripts/analyzer/features/return_variant_typed.gd b/modules/gdscript/tests/scripts/analyzer/features/return_variant_typed.gd new file mode 100644 index 0000000000..c9caef7d7c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/return_variant_typed.gd @@ -0,0 +1,5 @@ +func variant() -> Variant: + return 'variant' + +func test(): + print(variant()) diff --git a/modules/gdscript/tests/scripts/analyzer/features/return_variant_typed.out b/modules/gdscript/tests/scripts/analyzer/features/return_variant_typed.out new file mode 100644 index 0000000000..57fe608cc5 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/return_variant_typed.out @@ -0,0 +1,2 @@ +GDTEST_OK +variant -- cgit v1.2.3