From ed5ddab7e54c121726116e36604b062dc172a2d0 Mon Sep 17 00:00:00 2001 From: George Marques Date: Mon, 6 Feb 2023 14:52:13 -0300 Subject: GDScript: Fix inheritance check of @onready for inner classes --- .../scripts/analyzer/errors/onready_within_non_node_inner_class.gd | 7 +++++++ .../analyzer/errors/onready_within_non_node_inner_class.out | 2 ++ .../features/onready_on_inner_class_with_non_node_outer.gd | 7 +++++++ .../features/onready_on_inner_class_with_non_node_outer.out | 2 ++ 4 files changed, 18 insertions(+) create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/onready_within_non_node_inner_class.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/onready_within_non_node_inner_class.out create mode 100644 modules/gdscript/tests/scripts/analyzer/features/onready_on_inner_class_with_non_node_outer.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/features/onready_on_inner_class_with_non_node_outer.out (limited to 'modules/gdscript/tests') diff --git a/modules/gdscript/tests/scripts/analyzer/errors/onready_within_non_node_inner_class.gd b/modules/gdscript/tests/scripts/analyzer/errors/onready_within_non_node_inner_class.gd new file mode 100644 index 0000000000..1639bbbd52 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/onready_within_non_node_inner_class.gd @@ -0,0 +1,7 @@ +extends Node + +class Inner extends RefCounted: + @onready var nope = 0 + +func test(): + print("Cannot use @onready without a Node base") diff --git a/modules/gdscript/tests/scripts/analyzer/errors/onready_within_non_node_inner_class.out b/modules/gdscript/tests/scripts/analyzer/errors/onready_within_non_node_inner_class.out new file mode 100644 index 0000000000..8088d28329 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/onready_within_non_node_inner_class.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +"@onready" can only be used in classes that inherit "Node". diff --git a/modules/gdscript/tests/scripts/analyzer/features/onready_on_inner_class_with_non_node_outer.gd b/modules/gdscript/tests/scripts/analyzer/features/onready_on_inner_class_with_non_node_outer.gd new file mode 100644 index 0000000000..1ac03c2181 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/onready_on_inner_class_with_non_node_outer.gd @@ -0,0 +1,7 @@ +extends RefCounted + +func test(): + print("ok") + +class Inner extends Node: + @onready var okay = 0 diff --git a/modules/gdscript/tests/scripts/analyzer/features/onready_on_inner_class_with_non_node_outer.out b/modules/gdscript/tests/scripts/analyzer/features/onready_on_inner_class_with_non_node_outer.out new file mode 100644 index 0000000000..1b47ed10dc --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/onready_on_inner_class_with_non_node_outer.out @@ -0,0 +1,2 @@ +GDTEST_OK +ok -- cgit v1.2.3