diff options
author | George Marques <george@gmarqu.es> | 2024-04-16 11:16:36 -0300 |
---|---|---|
committer | George Marques <george@gmarqu.es> | 2024-04-16 11:46:59 -0300 |
commit | f9048fcd7d2bee9cc0a23a76269c52d637b6a5bf (patch) | |
tree | ec43e9c2ae9f5149c3b71202109ad0a0f245ef41 /modules/gdscript/tests/scripts/analyzer | |
parent | 658e97c93aa2533cb7b12f05e62dcf6864e7acbe (diff) | |
download | redot-engine-f9048fcd7d2bee9cc0a23a76269c52d637b6a5bf.tar.gz |
GDScript: Warn when enum variable has no default
The default will always be set to `0`, so if it's not a valid value in
the enum, the warning is shown.
Diffstat (limited to 'modules/gdscript/tests/scripts/analyzer')
-rw-r--r-- | modules/gdscript/tests/scripts/analyzer/warnings/enum_without_default_value.gd | 9 | ||||
-rw-r--r-- | modules/gdscript/tests/scripts/analyzer/warnings/enum_without_default_value.out | 7 |
2 files changed, 16 insertions, 0 deletions
diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/enum_without_default_value.gd b/modules/gdscript/tests/scripts/analyzer/warnings/enum_without_default_value.gd new file mode 100644 index 0000000000..13e3edf93f --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/enum_without_default_value.gd @@ -0,0 +1,9 @@ +enum HasZero { A = 0, B = 1 } +enum HasNoZero { A = 1, B = 2 } +var has_zero: HasZero # No warning, because the default `0` is valid. +var has_no_zero: HasNoZero # Warning, because there is no `0` in the enum. + + +func test(): + print(has_zero) + print(has_no_zero) diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/enum_without_default_value.out b/modules/gdscript/tests/scripts/analyzer/warnings/enum_without_default_value.out new file mode 100644 index 0000000000..ae40e0bc8c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/enum_without_default_value.out @@ -0,0 +1,7 @@ +GDTEST_OK +>> WARNING +>> Line: 4 +>> ENUM_VARIABLE_WITHOUT_DEFAULT +>> The variable "has_no_zero" has an enum type and does not set an explicit default value. The default will be set to "0". +0 +0 |