From 0a51bb4ca54fa9fd15b40dac28476eae6ff0c816 Mon Sep 17 00:00:00 2001 From: clayjohn Date: Thu, 13 Oct 2022 12:42:11 -0700 Subject: Add STATIC_CALLED_ON_INSTANCE warning to highlight when static functions are called directly from objects --- .../scripts/parser/warnings/static_called_on_instance.gd | 11 +++++++++++ .../scripts/parser/warnings/static_called_on_instance.out | 7 +++++++ 2 files changed, 18 insertions(+) create mode 100644 modules/gdscript/tests/scripts/parser/warnings/static_called_on_instance.gd create mode 100644 modules/gdscript/tests/scripts/parser/warnings/static_called_on_instance.out (limited to 'modules/gdscript/tests') diff --git a/modules/gdscript/tests/scripts/parser/warnings/static_called_on_instance.gd b/modules/gdscript/tests/scripts/parser/warnings/static_called_on_instance.gd new file mode 100644 index 0000000000..29d8501b78 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/warnings/static_called_on_instance.gd @@ -0,0 +1,11 @@ +class Player: + var x = 3 + +func test(): + # These should not emit a warning. + var _player = Player.new() + print(String.num_uint64(8589934592)) # 2 ^ 33 + + # This should emit a warning. + var some_string = String() + print(some_string.num_uint64(8589934592)) # 2 ^ 33 diff --git a/modules/gdscript/tests/scripts/parser/warnings/static_called_on_instance.out b/modules/gdscript/tests/scripts/parser/warnings/static_called_on_instance.out new file mode 100644 index 0000000000..3933a35178 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/warnings/static_called_on_instance.out @@ -0,0 +1,7 @@ +GDTEST_OK +>> WARNING +>> Line: 11 +>> STATIC_CALLED_ON_INSTANCE +>> The function 'num_uint64()' is a static function but was called from an instance. Instead, it should be directly called from the type: 'String.num_uint64()'. +8589934592 +8589934592 -- cgit v1.2.3