summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/tests/scripts/runtime/features/static_access_via_instance.gd
blob: 77d01cf00ce1735671aec5e41c9f4ccec6e8934d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# GH-77098 p.4

@static_unload

class A:
	class InnerClass:
		pass

	enum NamedEnum { VALUE = 111 }
	enum { UNNAMED_ENUM_VALUE = 222 }
	const CONSTANT = 333
	static var static_var := 1

	static func static_func() -> int:
		return 444

class B extends A:
	func test_self():
		print(self.InnerClass is GDScript)
		print(self.NamedEnum)
		print(self.NamedEnum.VALUE)
		print(self.UNNAMED_ENUM_VALUE)
		print(self.CONSTANT)
		@warning_ignore("static_called_on_instance")
		print(self.static_func())

		prints("test_self before:", self.static_var)
		self.static_var = 2
		prints("test_self after:", self.static_var)

func test():
	var hard := B.new()
	hard.test_self()

	print(hard.InnerClass is GDScript)
	print(hard.NamedEnum)
	print(hard.NamedEnum.VALUE)
	print(hard.UNNAMED_ENUM_VALUE)
	print(hard.CONSTANT)
	@warning_ignore("static_called_on_instance")
	print(hard.static_func())

	prints("hard before:", hard.static_var)
	hard.static_var = 3
	prints("hard after:", hard.static_var)

	var weak: Variant = B.new()
	print(weak.InnerClass is GDScript)
	print(weak.NamedEnum)
	print(weak.NamedEnum.VALUE)
	print(weak.UNNAMED_ENUM_VALUE)
	print(weak.CONSTANT)
	@warning_ignore("unsafe_method_access")
	print(weak.static_func())

	prints("weak before:", weak.static_var)
	weak.static_var = 4
	prints("weak after:", weak.static_var)