mirror of
https://github.com/godotengine/godot.git
synced 2026-01-05 06:11:29 +03:00
GDScript: Initialize all defaults beforehand in implicit constructor
Set all the default values for typed variables before actually trying to initialize them, including `@onready` ones. This ensures that if validated calls are being used there will be a value of the correct type, even if the resolution is done out of order or deferred because of `@onready`.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
extends Node
|
||||
|
||||
@onready var later_inferred := [1]
|
||||
@onready var later_static : Array
|
||||
@onready var later_static_with_init : Array = [1]
|
||||
@onready var later_untyped = [1]
|
||||
|
||||
func test():
|
||||
assert(typeof(later_inferred) == TYPE_ARRAY)
|
||||
assert(later_inferred.size() == 0)
|
||||
|
||||
assert(typeof(later_static) == TYPE_ARRAY)
|
||||
assert(later_static.size() == 0)
|
||||
|
||||
assert(typeof(later_static_with_init) == TYPE_ARRAY)
|
||||
assert(later_static_with_init.size() == 0)
|
||||
|
||||
assert(typeof(later_untyped) == TYPE_NIL)
|
||||
|
||||
print("ok")
|
||||
@@ -0,0 +1,2 @@
|
||||
GDTEST_OK
|
||||
ok
|
||||
Reference in New Issue
Block a user