godot
godot copied to clipboard
GDScript 2.0: Packed arrays are not considered constant expressions
Godot version
v4.0.beta3.official [01ae26d31]
System information
Kubuntu 22.10
Issue description
Attempting to use a packed array in a constant definition causes "Initializer for a constant must be a constant expression" error.
Steps to reproduce
# 3.x:
const A = PoolIntArray() # OK.
const B = PoolIntArray([1, 2, 3]) # OK.
# 4.0-dev:
const A = PackedInt32Array() # Error: Initializer for a constant must be a constant expression.
const B = PackedInt32Array([1, 2, 3]) # Error: Initializer for a constant must be a constant expression.
Minimal reproduction project
No response
See also:
- godotengine/godot-proposals#5653
related to https://github.com/godotengine/godot/issues/66949 introduced in https://github.com/godotengine/godot/commit/a604e72dc974723439e9df5edc67502b82beba4b
Also, we should not forget about readonly Packed*Array
s (make_read_only()
), for consistency with Array
and Dictionary
.
Also, we should not forget about readonly
Packed*Array
s (make_read_only()
), for consistency withArray
andDictionary
.
This might be tricky because Packed*Array
are just typedef
s for Vector<>
. Adding read-only functionality would affect all vectors used in core.
They could be made proper classes inheriting from Vector<>
and adding features, but that's a big change and should be discussed on its own merit.
This might be tricky because
Packed*Array
are justtypedef
s forVector<>
. Adding read-only functionality would affect all vectors used in core.
Yes, I was worried about it, and that's why I tried to draw attention to it yesterday. :)
I suggest deferring this to 4.2 or 4.x as 4.1 is in a feature freeze. Since this is more a lack of a new feature than a bug. Packed arrays have changed significantly in 4.0, they are now passed by reference rather than by value. And since they don't have a make_read_only()
method (unlike Array
and Dictionary
), we can't make them constant as it worked before on the GDScript side. Core changes are required, and now is not the time to experiment with such important engine structure as Vector<T>
. Please add the topic:core
label.