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:
parent
6296b46008
commit
0e6aa6fc38
3 changed files with 48 additions and 10 deletions
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue