-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] export var array reduced to const bug fixed #38976
[WIP] export var array reduced to const bug fixed #38976
Conversation
a8c3b64
to
077b2f2
Compare
077b2f2
to
0c43d17
Compare
Doesn't this break default values, e.g.:
|
@bojidar-bg even without export var z1 = Vector3(7,6,4)
export var z2 = Vector3(7,6,4)
func _ready():
z1.x = 12
print(z1)
print(z2)
pass
--the output--
(12, 6, 4)
(7, 6, 4) |
@ThakeeNathees I would still suggest the same thing as before: call That way there would be no regression for |
@bojidar-bg there is no regression for @@ -4926,6 +4926,12 @@ void GDScriptParser::_parse_class(ClassNode *p_class) {
if (autoexport && !member.data_type.has_type) {
if (subexpr->type != Node::TYPE_CONSTANT) {
_set_error("Type-less export needs a constant expression assigned to infer type.");
return;
}
ConstantNode *cn = static_cast<ConstantNode *>(subexpr);
if (cn->value.get_type() == Variant::NIL) {
_set_error("Can't accept a null constant expression for inferring export type.");
return;
}
if (!_reduce_export_var_type(cn->value, member.line)) {
return;
}
member._export.type = cn->value.get_type();
member._export.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE;
if (cn->value.get_type() == Variant::OBJECT) {
Object *obj = cn->value;
Resource *res = Object::cast_to<Resource>(obj);
if (res == nullptr) {
_set_error("The exported constant isn't a type or resource.");
return;
}
member._export.hint = PROPERTY_HINT_RESOURCE_TYPE;
member._export.hint_string = res->get_class();
}
+
+ if (cn->value.get_type() == Variant::ARRAY) {
+ subexpr = constant_node_to_array_node(cn);
+ } else if (cn->value.get_type() == Variant::DICTIONARY) {
+ subexpr = constant_node_to_dict_node(cn);
+ }
}
#ifdef TOOLS_ENABLED |
I'm at a loss. How does it work if default value is set only if the node is a ConstantNode: godot/modules/gdscript/gdscript_parser.cpp Line 4950 in 0c43d17
But godot/modules/gdscript/gdscript_parser.cpp Line 4879 in 0c43d17
Looks patchy to me. Why would we need to generate the |
even with out default value it's working may be default value is NIL variant not sure, but now we can set it a default value from my point 2. |
|
Any information on this? |
@andrew121410 thanks for pointing out. marking this as WIP for now. (#38976 (comment) TODOs), I'll complete this ASAP (in a couple of days) and It'll ready for reivew. |
@ThakeeNathees Hi! I saw your PR that fixed this issue for |
Superseded by #41983. |
Fix: #20436
it's working for every scenario above, (seems like only
Array
andDictionary
are exportable reference types)